Hello everybody. I'm pretty new to PHP and mysql. I made a mysql database table: Election_Table
One of the fields in there is elect_title, and the primary key is ID

I am trying to make a drop down menu that has the names of all the names of the elections (elect_title) in this table. I also need to pass whatever election the user chose to link with buttons with different functions. Say if I have a 'Status' button, I will choose a election from the drop down and click 'Status' button to see status (I will have a function called showStatus on this file that will handle this). Here's what i have so far: Nothing shows up

<?

$sql=mysql_query("SELECT elect_title FROM Election_Table") or die("Cannot retrieve names from election table");

$result=mysql_query($sql);

print($result);
$options="";

while ($row=mysql_fetch_array($result)) {

  $id=$row["elect_title"];
  $options.="<OPTION VALUE=\"$elect_title\">";
}

?>

Try this out instead.

<?
 
$sql=mysql_query("SELECT elect_title FROM Election_Table") or die("Cannot retrieve names from election table");
 
$result=mysql_query($sql);
 
print($result);
$options="";
 
while ($row=mysql_fetch_array($result)) {
 
  $id=$row["elect_title"];
  $options.="<OPTION VALUE=\"$id\">";
}
?>
<select name="elect_title">
<?=$options?>
</option>
</select>
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.