0

Hi i was just wondering if anyone knew how to generate a drop down menu with sql. The section of code i have that has to be changed is

<div>
<span class="bold">Choose a lecturer:</span><br>
<?php
   // note how the keyword "distinct" in the following query prevents duplicate values from being returned
   $dbQuery="select distinct lecturer from p3_modules";
   $dbResult=mysql_query($dbQuery,$db);
   // convert this loop to generate a drop down list (3a)
   // the value of each <option> element should be the lecturer's name
   // enclose the drop down list in a form with action=showModules.php 
   while ($dbRow=mysql_fetch_array($dbResult)) {
      $thisLecturer=$dbRow["lecturer"];
      echo "$thisLecturer<br>";
   }
   // add a submit button for the form
?>
</div>   
3
Contributors
4
Replies
7
Views
5 Years
Discussion Span
Last Post by diafol
0

Something like this?

$output = "\n<select name=\"myname\">";
while(....){
   $output .= "\n\t<option value=\"{$dbRow['lecturer_id']}\">{$dbRow['lecturer']}</option>";
}
$output .= "\n</select>";

...
echo $output;
0

try,

<div>
<span class="bold">Choose a lecturer:</span><br>
<select name="lecturer" >
<?php
// note how the keyword "distinct" in the following query prevents duplicate values from being returned
$dbQuery="select distinct lecturer from p3_modules";
$dbResult=mysql_query($dbQuery,$db);
// convert this loop to generate a drop down list (3a)
// the value of each <option> element should be the lecturer's name
// enclose the drop down list in a form with action=showModules.php
while ($dbRow=mysql_fetch_array($dbResult)) {
 echo '<option name="'.$dbRow['id'].'" >'.$dbRow['lecturer'].'</option>';

}

// add a submit button for the form
?>
</select>
<input type="submit" name="submit" value="Submit"/>
</div>

Edited by veedeoo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.