It's been a while since i posted in here, but last time i got a great response and was sorted out quickly, so fingers crossed someone can spot the mischievous bit of code that is causing me problems and help me out :)
I am populating a drop down menu from a DB. I have sub categories and articles within those Subcats. I want the drop down to list the sub categories, then if there is only ONE article attached to that Subcat then it ges to a paage to display that article. If there are more than one, then it goes to a page that lists the articles for the user to choose.
I had the code working fine to display when just one article is assigned to each subcat. It even works when there is more than one.
HOWEVER, the problem is that if there is more than one article per subcat, it repeats the subcat name in the drop down. So if there are two articles, it lists the subcat twice, three articles shows three subcats, etc.
anyone able to look through the code and see where i am going wrong? :) pretty please? :)
many thanks in advance!
---lots of other php stuff up here, including an if statement just before the cut off point---
$catid = $rowCat['cat_id']; } // end if isset
$subcatSQL = "SELECT DISTINCT c.cat_id, c.cat_title, c.cat_parentid, c.cat_type, c.cat_visible"; $subcatSQL .= " FROM tbl_cats c"; $subcatSQL .= " WHERE c.cat_visible=1 AND c.cat_parentid = '$catid'"; $subcatSQL .= " AND c.cat_type LIKE 'articles%'"; $subcatSQL .= " ORDER BY c.cat_id ASC"; $rsSubCat = mysql_query($subcatSQL, $conn) or die("Query failed : " . mysql_error()); while($rowSubCat = mysql_fetch_array($rsSubCat)){
$subcatid = $rowSubCat['cat_id'];
$artSQL = "SELECT a.art_id, a.art_title, a.art_visible, ac.artcat_artid, ac.artcat_catid"; $artSQL .= " FROM tbl_articles a, tbl_art_cats ac"; $artSQL .= " WHERE ac.artcat_catid = '$subcatid' AND ac.artcat_artid = a.art_id"; $artSQL .= " ORDER BY a.art_id ASC"; $rsArt = mysql_query($artSQL, $conn) or die("Query failed : " . mysql_error()); $num_rows = mysql_num_rows($rsArt);
while($rowArt = mysql_fetch_array($rsArt)){
if ($num_rows > 1) { ?>
} elseif ($num_rows = 1) { ?>
} //end of elseif
} // end rowart while } //end rowsubcat while } // end of rowcat while ?>