Jump to content

Display data from category and data from all sub categories within that category


superman50

Recommended Posts

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>";


}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.