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


}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.