Newbie having problems with nested while loops...
Posted: Wed Aug 08, 2007 3:30 pm
feyd | Please use
So, when someone comes back to the form I want to show which boxes should be pre-checked based on the data in table2. I tried a nested loop and only get it to return the first row. I thought I saw something somewhere about resetting the variables but I'm not sure what to do and if there is a better way to go about doing this. I have something like this right now...
Any suggestions on what I should do, or what I am doing wrong?
Thanks.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Here is the simple version of what I'm trying to do:
Creating a preference center for "favorite cars"...
table1 - id, carname (30 rows)
table 2 - uid, carid (2 rows) - it's just one user right now that I'm testing against and he only "likes" 2 of the 30 possible cars
form with check boxes displays all 30 cars and allows user to check which are their favorites.
Form page is built with a while loop to create all the check boxesCode: Select all
while ($row = mysql_fetch_array($table1)) {
create all the form fields
}Code: Select all
while ($row = mysql_fetch_array($table1)) {
while ($row2 = mysql_fetch_array($table2)) {
if ($row[id] = $row2[carid]) {
create all the form fields with checks
} else {
create all the other form fields
}
}
}Thanks.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]