On Friday 21 June 2002 10:31, bob wrote:
> 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";
>    }
> ?>

Here your $category_list will be a string like 'Category1Category2...', which 
is probably not what you want.

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

Instead of doing two loops (while and for) just have a single while loop, 
build your <option value...> inside the while loop.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
NOWPRINT. NOWPRINT. Clemclone, back to the shadows again.
- The Firesign Theater
*/


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

Reply via email to