RE: foreach loop from MySQL select query to HTML select list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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...



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux