MYSQL using dropdown list

Discussion in 'PHP' started by koscek, Oct 29, 2007.

  1. #1
    <?php require_once('Connections/kioks.php'); ?>
    
     
    <?php
    mysql_select_db($database_kioks, $kioks);
    $query_ListDept = "SELECT * FROM department";
    $ListDept = mysql_query($query_ListDept, $kioks) or die(mysql_error());
    $row_ListDept = mysql_fetch_assoc($ListDept);
    $totalRows_ListDept = mysql_num_rows($ListDept);
    
    $maxRows_ListLect = 10;
    $pageNum_ListLect = 0;
    if (isset($HTTP_GET_VARS['pageNum_ListLect'])) {
      $pageNum_ListLect = $HTTP_GET_VARS['pageNum_ListLect'];
    }
    $startRow_ListLect = $pageNum_ListLect * $maxRows_ListLect;
    
    $colname_ListLect = "0";
    if (isset($HTTP_POST_VARS['menu1'])) {
      $colname_ListLect = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['menu1'] : addslashes($HTTP_POST_VARS['menu1']);
    }
    mysql_select_db($database_kioks, $kioks);
    $query_ListLect = sprintf("SELECT * FROM lecturer WHERE Department_Code = '%s' ORDER BY lecturer.Lecturer_Name", $colname_ListLect);
    $query_limit_ListLect = sprintf("%s LIMIT %d, %d", $query_ListLect, $startRow_ListLect, $maxRows_ListLect);
    $ListLect = mysql_query($query_limit_ListLect, $kioks) or die(mysql_error());
    $row_ListLect = mysql_fetch_assoc($ListLect);
    
    if (isset($HTTP_GET_VARS['totalRows_ListLect'])) {
      $totalRows_ListLect = $HTTP_GET_VARS['totalRows_ListLect'];
    } else {
      $all_ListLect = mysql_query($query_ListLect);
      $totalRows_ListLect = mysql_num_rows($all_ListLect);
    }
    $totalPages_ListLect = ceil($totalRows_ListLect/$maxRows_ListLect)-1;
    
    $colname_dept = "0";
    if (isset($HTTP_POST_VARS['menu1'])) {
      $colname_dept = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['menu1'] : addslashes($HTTP_POST_VARS['menu1']);
    }
    mysql_select_db($database_kioks, $kioks);
    $query_dept = sprintf("SELECT * FROM department WHERE Department_Code = '%s'", $colname_dept);
    $dept = mysql_query($query_dept, $kioks) or die(mysql_error());
    $row_dept = mysql_fetch_assoc($dept);
    $totalRows_dept = mysql_num_rows($dept);
    ?>
    <html>
    <head>
    <title>Lecturer Info</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    
    <body bgcolor="82ccdc">
     
    <table bgcolor="#c5edf5"  width="43%" height="363" align="center" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
      <form name="dept" action="" method="post">
       <tr>
        <td valign="top">
    	        <tr> 
              <td height="18" valign="top">
                <?php include 'includes/header.php'; ?>
              </td>
            </tr> 
          <tr valign="top"> 
          <td><hr class=lineBlack></td>
        </tr>
        <tr>
          <td height="44" align="center">
    <p><font size="2" color="#286370"><strong>&nbsp; 
              <label>Please select department</label>
              </strong>
              <label></label>
              </font>
              <label></label>
            </p>
            <p> 
              <select name="menu1" id="menu1" onChange="dept.submit();">
                <option value="">Select Department</option>
                <?php
    do {  
    ?>
                <option value="<?php echo $row_ListDept['Department_Code']?>"><?php echo $row_ListDept['Deparment_Description']?></option>
                <?php
    } while ($row_ListDept = mysql_fetch_assoc($ListDept));
      $rows = mysql_num_rows($ListDept);
      if($rows > 0) {
          mysql_data_seek($ListDept, 0);
    	  $row_ListDept = mysql_fetch_assoc($ListDept);
      }
    ?>
              </select>
            </p>
            </td>
        </tr>
      
    </form>
    <form method="get">
    <tr>
    <td>
      <table width="100%" height="100%" align="center" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
              <?php if ($totalRows_dept > 0) { // Show if recordset not empty ?>
        <tr> 
          <td><strong><font color="#286370" size="2">Department</font></strong></td>
                <td colspan="2"><font color="#286370" size="2"> 
                  <?php echo $row_dept['Deparment_Description']; ?></font></td>
        </tr>
        <?php } // Show if recordset not empty ?>
        
        <tr> 
                <td colspan="3">&nbsp;</td>
        </tr>
        <?php if ($totalRows_ListLect > 0) { // Show if recordset not empty ?>
        <tr> 
                <td width="43%" height="17" bgcolor="82ccdc">
    <div align="left"><font color="#286370" size="2"><strong>Name</strong></font></div></td>
          <td width="29%" bgcolor="82ccdc"><div align="left"><font color="#286370" size="2"><strong>Ext</strong></font></div></td>
          <td width="25%" bgcolor="82ccdc"><div align="left"><font color="#286370" size="2"><strong>Room 
              No.</strong></font></div></td>
        </tr>
    	<tr>
                <td height="23" colspan="3">&nbsp;</td>
              </tr>
        <?php do { ?>
        <tr> 
          <td><strong><font color="#286370" size="2"><a href="LecturerInfo.php?id=<?php echo $row_ListLect['Lecturer_ID']; ?>"><?php echo $row_ListLect['Lecturer_Name']; ?> </a> </font></strong></td>
          <td><strong><font color="#286370" size="2"><?php echo $row_ListLect['Lecturer_Phone']; ?></font></strong></td>
          <td><strong><font color="#286370" size="2"><?php echo $row_ListLect['Lecturer_Room']; ?></font></strong></td>
        </tr>
        <?php } while ($row_ListLect = mysql_fetch_assoc($ListLect)); ?>
        <tr> 
                <td colspan="3" align="left" bgcolor="82ccdc"><font color="#286370" size="2"><strong> 
                  Previous || Next </strong></font></td>
        </tr>
        <?php } // Show if recordset not empty ?> 
      </table>
    </form>
    </td>
    </tr>
    </table>
    </body>
    </html>
    <?php
    mysql_free_result($ListLect);
    
    mysql_free_result($ListDept);
    
    //mysql_free_result($ListLect);
    
    mysql_free_result($dept);
    ?>
    
    PHP:

    i have this code. when i add into windows apache server its running great....but not in linux(fedora7) apache server... why?

    when i select the choice from the drop down box...the list in drop down box is get from mysql,here is no problem....but there nothing output/result, which is from mysql...why?
     
    koscek, Oct 29, 2007 IP
  2. Edynas

    Edynas Peon

    Messages:
    796
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ...maybe obvious... but you are sure that you have a connection to the db when you use linux?
     
    Edynas, Oct 30, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    Let me rephrase to make sure I understand. You see the select box on the Linux server, but there are no options to select?

    If that's the case the above comment would not make sense as there are die()s before any output is sent at all if one of the queries fails.


    Try to avoid do {} while loops, specially for looping over database results. Try this instead:

    
    while ($row_ListDept = mysql_fetch_assoc($ListDept))
    {
    ?>
      <option value="<?php echo $row_ListDept['Department_Code']?>"><?php echo $row_ListDept['Deparment_Description']?></option>
        <?php
    } 
    
    PHP:
    If that does not work, set these lines on top of your code and see if you get any errors.

    
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
    PHP:
     
    nico_swd, Oct 30, 2007 IP