Hi all PHP Gurus..
iam trying to develop a catalog, i've started with the main navigation of
products.. im almost half away, the rest, i could not figure it out.. so here i
am ..
the problem with this code is.. iam able to reach to any sub-branch of the tree,
the only thing whic is left .. i dont know how to Expand or Collapse a paticular
branch, thus ending with opend branch for clicked item..to get to know what iam trying to understand pls visit:
http://www.dubaidesigns.com/mytree2.php?CatPrntID=0
this will begin from the root of the tree..
Here is the PHP code.. you can find the table and DB structure below as well..
<code>
#-----connection -----------
$localhost="localhost";
$user="user";
$pwd="password";
$dbname="mydb";
$connection=mysql_connect ("$localhost","$user","$pwd");
mysql_select_db ($dbname);
#------------------
if($query=="")
{
$query="SELECT * FROM categories WHERE CatPrntID=$CatPrntID"; //Category ParentID
}
else
{
$query = $HTTP_GET_VARS["query"];
$query = urldecode($query);
$query .= " OR CatPrntID=$CatPrntID";
}
$aa .= $query;
$aa .= " Order By CatID";
$result = mysql_query($aa);
echo "<font face=arial size=1><b>Excuted Query: <br>$aa</b></font><br>";
if(!$result)
{
echo mysql_error();
echo "<b>Query retured error!</b><br>$query";
}
else
{
while ($record = mysql_fetch_array($result))
{
$CatID=$record[0]; //category id
$CatPrntID=$record[1]; //category parent id
$CatLvlID=$record[2]; //category level id
$CatNm=$record[3]; // category name
echo("<a href=\"$PHP_SELF?CatPrntID=$CatID&query=" .
urlencode($query) . "\">$CatID $CatNm</a><br>");
}
}
mysql_close($connection);
</code>
#MYSQL Table Structure & Sample Data-----------------
CREATE TABLE categories (
CatID varchar(15) NOT NULL default '',
CatPrntID varchar(15) default NULL,
CatLvlID tinyint(4) NOT NULL default '0',
CatNm varchar(50) NOT NULL default '0',
CatLtnNm varchar(50) NOT NULL default '',
PRIMARY KEY (CatID)
) TYPE=MyISAM;
Dumping data for table categories
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('01', '0', 0, 'Tiles', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('0101', '01', 1, 'Wall', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('0102', '01', 1, 'Floor', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('010101', '0101', 2, 'Kitchen', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('010102', '0101', 2, 'Dining', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('010103', '0101', 2, 'Bathroom', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('01010101', '010101', 3, 'Spring 2001', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('01010102', '010101', 3, 'Summer 2001', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('0101010101', '01010101', 4, 'Set 1', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('0101010102', '01010101', 4, 'Set 2', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('02', '0', 0, 'Ceramic', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('03', '0', 0, 'Sanitary Ware', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('0201', '02', 1, 'Granite', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('0202', '02', 1, 'Porcelain', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('0301', '03', 1, 'Bath Tubs', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('0302', '03', 1, 'Jacuzzi', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('030101', '0301', 2, 'Stainless Steel', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('030102', '0301', 2, 'Porcelain', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('03010101', '030101', 3, 'Vitra', '');
INSERT INTO categories (CatID, CatPrntID, CatLvlID, CatNm, CatLtnNm) VALUES ('03010102', '030101', 3, 'RAK', '');