Getting confused over looping
Posted: Tue Jan 18, 2005 10:30 pm
Me again. 
I think I've tied myself in a mental knot and just spent too long looking at this code. Can someone please have a look at this:
The results of this code can be seen if you go here http://www.dare2.com.au/productsservices.php and select one or more sections and the submit the form.
The way I've written it, it outputs the same section's content over and over. What is supposed to happen is that it displays the graphic for the category's heading if anything in that category has been selected and then displays each selected section under that category before going off to the next one.
Can someone please help me re-order my code so that the right things happen in the right places? I just can't seem to figure out what I'm doing wrong and it's driving me nuts.
I think I've tied myself in a mental knot and just spent too long looking at this code. Can someone please have a look at this:
Code: Select all
if (isset($g_submit)) {
$sql3 = "SELECT * FROM $table";
$result3 = mysql_query($sql3,$link);
foreach ($_GETї"Sections"] as $sect) {
$sect = explode(",",$sect);
$headed = "false";
while ($row3 = mysql_fetch_array($result3, MYSQL_ASSOC)) {
if (($row3ї"ID"] == $sectї0]) && ($headed == "false")) {
print "<img src="" . $row3ї"TitleImage"] . "" alt="" . $row3ї"CategoryName"] . "" class="titleImage" />";
$headed = "true";
} // if
$sql4 = "SELECT * FROM $table2 WHERE ID = $sectї1]";
$result4 = mysql_query($sql4,$link);
$row4 = mysql_fetch_array($result4, MYSQL_ASSOC);
print "<h2>" . $row4ї"SectionName"] . "</h2>";
print $row4ї"Description"] . "</p>";
} // while
} //foreach
} // ifThe way I've written it, it outputs the same section's content over and over. What is supposed to happen is that it displays the graphic for the category's heading if anything in that category has been selected and then displays each selected section under that category before going off to the next one.
Can someone please help me re-order my code so that the right things happen in the right places? I just can't seem to figure out what I'm doing wrong and it's driving me nuts.