RE: [PHP-DB] foreach loop from MySQL select query to HTML select list

From: Date: Thu, 28 Nov 2002 15:58:34 +0000
Subject: RE: [PHP-DB] foreach loop from MySQL select query to HTML select list
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-23719@lists.php.net to get a copy of this message
> i've looked around the web a bit more & it would appear you can't just use > a > foreach function, apparently you need to use a while{foreach{}} structure. > i > was hoping you could just use the foreach function? > > so this is the code now: > > <select name="deptsub_select"> > <option>-select-</option> > <?PHP > while ($row = mysql_fetch_array($result_deptsub)){ > foreach ($row as $value) { > echo "<option value=\"$value\">$value</option>\n"; Where did you get the idea to use foreach? Your select statement is only selecting one column, so $row is only going to have one column in it for each mysql_fetch_*. Use something like this: while($row = mysql_fetch_array($result_deptsub)) { echo "<option value=\"{$row['deptsub']}\">{$row['deptsub']}</option>\n"; } ---John Holmes...

« previous php.db (#23719) next »