RE: [PHP-DB] Populating multi-select list from mysql
| From: | Martin Clifford | Date: | Fri, 21 Jun 2002 16:20:11 +0000 |
| Subject: | RE: [PHP-DB] Populating multi-select list from mysql | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-19966@lists.php.net to get a copy of this message | ||
Whenever you are having trouble with your PHP pages, always echo! By doing this, you can see
whether or not the query is formatted correctly, whether or not the variables are containing the
values you think they are. It's incredibly helpful, no matter what the situation.
Martin
>>> "Ryan Jameson (USA)" <RJameson@usa.ibs.org> 06/21/02 12:10PM
>>> >>>
You're logic seems to make sense. The output (page source) you are getting would help. :-)
<>< Ryan
-----Original Message-----
From: Gary.Every@ingramentertainment.com
[mailto:Gary.Every@ingramentertainment.com]
Sent: Friday, June 21, 2002 10:06 AM
To: subscriptions@nhinsights.com; php-db@lists.php.net
Subject: RE: [PHP-DB] Populating multi-select list from mysql
Hi all,
I'm having problems getting my multi-select list populated from a mysql
table. There is a table called categories with 2 columns (id and category).
I want to get all the items (category) and list them in the multi-select
list box.
This is the code I have so far:
$sql = "SELECT category FROM categories";
$result = mysql_query($sql, $connection);
//Try This instead of the while statement
foreach($result as $row) {
echo '<OPTION VALUE="' . $row['category'] . '">' .
$row['category'];
}
echo '</select>';
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$category = $row['category'];
$category_list .= "$category";
}
?>
<select name=category_list_array[] multiple size=10>
<?
for ($i=0; $i<count($category_list); $i++) {
?>
<option value=<?=$category_list[$i]?>><?=$category_list[$i]?></option>
<?}?>
</select>
Now, if I echo $category_list to the page I can see I have the correct data,
I just can't get it into the list box. I've seem to hit a wall on any
different ways to try and make this work. What am I doing wrong?
Thanks.
Rob.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php