0

hi i'm having trouble creating a drop down menu using data from the database and i dont understand where the problem is

<?php
....
$conn ...blah blah blah...
mysql_select_db ...blah blah blah...
....

$query = mysql_query("SELECT * FROM teamdb WHERE sports='Basketball'");
$options = "";
	
while($row = mysql_fetch_array($query))
{
	$teamid = $row["teamid"];
	$teamname = $row["teamname"];
	$options.="<option value=\"$teamid\">".$teamname."</option>";
}

....
?>
<html>
....

<select name='whatever'>
<option value=0> choose</option>
<?=$options?>
</select>

....
</html>

the drop down menu created from this code only has the choose option
and i dont understand whats wrong with it
can anybody help?

and after that is fixed
if i want to put that while loop into a function so i choose which sport to create the menu for.
i just need :
function selectteam ($where)
put the query ... while loop into the function
and change the WHERE field to '$where'
right?

thanks for any help in advance

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by simplypixie
0

Firstly, to correct your script:

<?php
....
$conn ...blah blah blah...
mysql_select_db ...blah blah blah...
....

$query = mysql_query("SELECT * FROM teamdb WHERE sports='Basketball'");

....
?>
<html>
....

<select name='whatever'>
<?php
while($row = mysql_fetch_array($query))
{
echo '<option value"='.$row['teamid'].'">'.$row['teamname'].'</option>';	

}
?>
</select>

....
</html>
This question has already been answered. 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.