Forum Moderators: coopster
ID and Name
I want to call these into a HTML form drop down select menu, how would i go about this?
my sql query would be
select id, name from db;
this would list several rows which i would like each to be selectable in the HTML form.
<form action="something.php" method="post">
<select name="ID select">
<option>ROW1
<option>ROW2
<option>ROW3
<option>ROW4
<option>ROW5
<option>ROW6
<option>ROW7
</select>
I want this so that if a new id is added to the db, then a new option is created automatically, also the same if one is taken away, the option is removed.
Cheers
$sql = "select id, name from table order by name";
$resultSet = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($resultSet) > 0)
{
while($data = mysql_fetch_row($resultSet)){
$html_options .= "<option value=\"".$data['id'].""\">".$data['name']."</option>";
}
}
and the HTML should looks like:
<select name="Id">
<?=$html_options?>
</select>
if(mysql_num_rows($resultSet) > 0)
{
while($data = mysql_fetch_row($resultSet)){
$html_options .= "<option value=\"".$data['id'].""\">".$data['name']."</option>";
}
}
?>
<form action="winner.php" method="get">
<select name="Id">
<?=$html_options?>
</select>
</form>
After hosting this, the page is just blank, where am i going wrong?
Cheers
The SQL i want to run on submit is
select competition_entry.competition_id, user.user_id, email_address,
first_name, last_name, gender, date_of_birth, telephone_number,
address1, address2, address3, town, county, postcode
from competition_entry, user
WHERE competition_entry.competition_id ='#*$!#*$!'
ORDER BY RAND() limit 1\G
The #*$!#*$! is replaced by the string selected in the drop down menu i made
<option value ="<?=$row['id'];?>"><?=$row['name'];?> </option>
so .competion_id should be $row['id']?
I then want to echo the result. If submit is pushed again, i want the script to run again.
cheers for any help.