Forum Moderators: coopster

Message Too Old, No Replies

loop loop and more loop

trying to check values from a table

         

whizzy

4:30 am on Jun 30, 2003 (gmt 0)

10+ Year Member



Ok I got two tables in my database. One with categories, and one whitch contains selected categories by users.
So what I want to do is to list out all the categories in a list, and for each category in the list that the current user has selected before should be checked.

This is my code:

<select name="select" size="10" multiple>
<?php
echo $cat_row['cat_id'];
//$category is everything from my category table whitch contains all the categories
while ($category_row = mysql_fetch_array($category)) {
// $cat is everything from table user_category
while ($cat_row = mysql_fetch_array($cat)) {
if ($category_row['cat_id'] == $cat_row['cat_id']) {
echo "<option selected value=".$category_row['cat_id'].">".$category_row['cat_name']."</option>";
} else {
echo "<option value=".$category_row['cat_id'].">".$category_row['cat_name']."</option>";
}
}
}
?>
</select>

Hope you understand this code...its a bit messy.... :)

jatar_k

4:55 pm on Jun 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



so is it not working at all then whizzy? I don't really know what the question is.

whizzy

1:40 am on Jul 1, 2003 (gmt 0)

10+ Year Member



ok...

My category table has 10 records.
My user_cat table has 2 records on the current user.
When the current user load the page, the listbox should display all the 10 records from the category table, but highlight those that he has selected before.

Not sure if thats any better but...

So when I run my current code, I only get two records. and thats not even the one thats in the user_cat table.

Any ideas?