Weird nested while loop problem
| From: | Maurice Rickard | Date: | Wed, 17 Jan 2001 21:20:32 +0000 |
| Subject: | Weird nested while loop problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-35154@lists.php.net to get a copy of this message | ||
In my attempt to simulate array_intersect in PHP3, I tried nesting while statements. While traversing one array to display checkboxes, I wanted to loop through another array, testing to see if any of the values in it match the current value in the outer while loop.
What I'm getting is that the inner while loop executes on the first execution of the outer while, and then not at all. How would I get it to execute each time?
Here's the code:
$childquery = "select * from flavors order by flavor";
$childtype = "flavor";
$childresult = mysql_query($childquery) or die(mysql_error());
$relationsquery = "select * from relations where childtype='$childtype' and parenttype='$parenttype' and parentsku='$parentsku'";
$relationsresult = mysql_query($relationsquery) or die(mysql_error());
?>
<form action="<?php echo $PHP_SELF?>" method="post">
...various form variables...
<h3>Parent: <?php echo $parent ?></h3>
<?php
while ($row = mysql_fetch_array($childresult)) {
$thevalue = $row["flavorsku"];
$thedisplay = $row["flavor"];
printf("<input type=\"checkbox\" name=\"childsku[]\" value=\"%s\"", $thevalue);
while ($relationsrow = mysql_fetch_array($relationsresult)) {
$thischild = $relationsrow["childsku"];
if ($thevalue == $thischild) {
echo " checked";
}
} // end while relations loop
printf(">%s<br>\n", $thedisplay);
} //end the child results while loop
Thanks for any suggestions!
--
Maurice Rickard
http://mauricerickard.com/