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>   
Member Avatar for diafol

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;

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>

Thank you veedeoo this worked :)

Member Avatar for diafol

mark it solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.