I am trying to list products under headings, but when I run this, I get the right headings, but the sub categories under the headings just duplicate. How can I fix this?
[code=php]<?
$query = mysql_query(“SELECT *
FROM product_list_main”);
if (mysql_affected_rows() > 0) {
while($row = mysql_fetch_array($query)){
$cat = $row[‘main_category’];
// Heading for the section
echo ‘<h2>’.strtoupper ($cat).'</h2>’;
$query2 = mysql_query(“SELECT *
FROM product_list_sub
WHERE mainProdID = ‘$cat'”);
if (mysql_affected_rows() > 0) {
while($row2 = mysql_fetch_array($query2)){
$description = $row2[‘description’];
$name = $row2[‘name’];
$prodID = $row2[‘id’];
# All of the sub-items listed here
?>
<? echo $name; ?> [<a href=”#” rel=”modal-profile” id=”<? echo $prodID; ?>” class=”product_quickview”>QUICKVIEW</a>]<br />
<?
}
}
}
}
?>