superman50 Posted July 13, 2009 Share Posted July 13, 2009 I’m trying to make the script which I have to display data from a category and also all data from the category sub category. Obviously what I’m trying to do is, Category 1 Sub Cat 1 (12 data) Sub Cat 2 (10 data) Sub Cat 3 (5 data) So when user clicks on Category 1, all subcategory data “Sub Cat 1” “Sub Cat 2” etc will display. And when user click on Sub Cat 1, only the Sub Cat 1 data will display. The current script has sub category function but it’s not working the way I want. I have paste the category page script here. I tried to modify the $catSQL to include the parented but its not working. It return full of MySQL error. Anyone have any idea? if ($_GET['catid']) { $catSQL = "SELECT * FROM category WHERE catID = ".$_GET['catid']; $catresult = mysql_query($catSQL); $catrow = mysql_fetch_array($catresult); //$displayCat = "<a href='index.php?action=browser&catid=".$catrow['catID']."'>".$catrow['catDesc']."</a>"; $displayCat = $catrow['catDesc']; $catLongDesc = $catrow['catLongDesc']; if ($catrow['parentID']) { $parentID = $catrow['parentID']; while ($parentID != 0) { $SQL1 = "SELECT * FROM category WHERE catID=$parentID"; $result1 = mysql_query($SQL1); $row1 = mysql_fetch_array($result1); $displayCat = "<a href='index.php?action=browser&catid=".$row1['catID']."'>".$row1['catDesc']."</a>" . " > " . $displayCat; $parentID = $row1['parentID']; } } echo "<div id=\"right-sub-navi_\"><a href='".FILE_INDEX."?action=category'>Category</a> / $displayCat</div>"; echo "<p>$catLongDesc</p>"; } Quote Link to comment https://forums.phpfreaks.com/topic/165842-display-data-from-category-and-data-from-all-sub-categories-within-that-category/ Share on other sites More sharing options...
ignace Posted July 13, 2009 Share Posted July 13, 2009 SELECT * FROM category WHERE catID=$parentID must be SELECT * FROM category WHERE parentID=$parentID Quote Link to comment https://forums.phpfreaks.com/topic/165842-display-data-from-category-and-data-from-all-sub-categories-within-that-category/#findComment-874770 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.