Populating multi-select list from mysql
| From: | bob | Date: | Fri, 21 Jun 2002 02:31:55 +0000 |
| Subject: | Populating multi-select list from mysql | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-19925@lists.php.net to get a copy of this message | ||
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);
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.