Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating dynamic drop-down list 1

Status
Not open for further replies.

smashing

Programmer
Oct 15, 2002
170
US
Am new to PHP. I wanna dynamicly fill a drop-down menu from:

$table_name ="fromny";
$doweek ="monthu";
//this is part of an if statement, the values of $table_name & of $doweek will have changed depending on user input

$sql = "SELECT leaving AND $doweek FROM $table_name";
$result = @mysql_query($sql, $connection)or die(mysql_error());
$row = mysql_fetch_array($result);
$option_block .= &quot;<option value=\&quot;a\&quot;>$row[]</option>&quot;;

and the in the html flow later on in the page:

<select name=&quot;selectName&quot; size=&quot;1&quot;>
<? echo &quot;$option_block&quot;; ?>
</select>



Where have I gone wrong?
 
Change
[tt]$row = mysql_fetch_array($result);
$option_block .= &quot;<option value=\&quot;a\&quot;>$row[]</option>&quot;;[/tt]
to
[tt]while ($row = mysql_fetch_array($result))
{
$option_block .= &quot;<option value=\&quot;a\&quot;>&quot; . $row[$doweek] . &quot;</option>&quot;;
}[/tt]
or something similar. You would probably want to change the value of the option tag to something else though, as the current code would just give all selections the same value. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top