I am trying to design/develop a category layout view that spans across multiple pages.
Page1 will list all categories with a parent_id of null
Once one of those categories are clicked, it will then open a new page (dynamically created) listing all the subcatategories for the category clicked on Page1.
E.G.
Page1.php lists all categories with parent_id NULL - Click on CategoryA(CATID=1)
Page2.??? dynamically created listing all categories with a parent_id of 1.
I can get it to list all categories with the parent_id of NULL, but that’s as far as I can go
SQL TABLE:
CREATE TABLE `categories_docs` (
`CATID` bigint(20) NOT NULL auto_increment,
`name` varchar(120) NOT NULL default '',
`parent_id` bigint(20) NOT NULL default '0',
PRIMARY KEY (`CATID`),
UNIQUE KEY `name` (`name`)
PHP:
//
// always list main categories:
//
$query = "SELECT * FROM categories_docs where parent_id='0' ORDER BY name asc";
$result = mysql_query($query) or die(mysql_error());
$currentCat = false;
while($row = mysql_fetch_array($result))
{
//so it doesn't repeat
if($currentCat != $row['CATID'])
{
echo "<div class=\\"media-box\\">
<img src=\\"https://pbs.twimg.com/profile_images/3722291655/d4b76926c35491a1c83b5bd4099330a6_normal.jpeg\\" alt=\\"\\" />
<br /><b>
<a href=\\"categories.php?CATID=" . $row['CATID'] . "&parent_id=" . $row['parent_id'] . "\\">" . $row['name'] . "</a></b>
</div>
";
$currentCat = $row['CATID'];
}
//subcategory output
}
//
// list sub subcategory if required:
//
$parent_id = isset($_GET["parent_id"]) ? $_GET["parent_id"] : "0";
$CATID = isset($_GET["CATID"]) ? $_GET["CATID"] : "";
//
if(! (($parent_id == "0") || empty($CATID)))
{
$query = "SELECT * FROM categories_docs where parent_id='$parent_id' AND CATID=$CATID ORDER BY name asc";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<div class=\\"media-box\\">
<img src=\\"https://pbs.twimg.com/profile_images/3722291655/d4b76926c35491a1c83b5bd4099330a6_normal.jpeg\\" alt=\\"\\" />
<br /><b>
<a href=\\"categories.php?parent_id=0" . "\\">Parent cat of " . $row['name'] . "</a></b>
</div>
";
}
}?>
I have also uploaded a quick and dirty html view to http://clients.silversitemedia.com/test/ - Page1.html is the start page
Any help would be GREATLY appreciated!
Thanks in advance!