...

View Full Version : Directory Question...



dizz
03-23-2004, 02:49 AM
Hi all,
I am setting up a directory similar to Yahoo. I am having problems displaying the parent categories though.

Also this forum uses the same concept:
CodingForums.com > :: Server side development > PHP > Directory Question...

I want to have it set up like:

Parent > Sub 1 > Sub 2

But I can only get it to show either:

Parent > Sub 1

Sub 1 > Sub 2

Also a category's parent with the value of 0 means that their is no parent category.



//Check to see if category has a parent category
function hasParent($parent){
if($parent>0){
//do{
$q2=mysql_query("SELECT * FROM categories WHERE id=$parent")or die(mysql_error());
$r2=mysql_fetch_array($q2);
$newparent=$r2['parent'];
$parentname=$r2['name'];
$newpath="$parentname > ";
$path="$newpath$path";
//}while($newparent>=0);
return $path;
}
else{
$path="";
return $path;
}
}


Any help would be awesome. Thanks in advance!

sweenster
03-23-2004, 01:08 PM
look like you have your WHILE in the wrong place. try this:



function hasParent($parent){
$newparent=$parent;
while($newparent>=0)
{
if($parent>0){

$q2=mysql_query("SELECT * FROM categories WHERE id=$parent")or die(mysql_error());
$r2=mysql_fetch_array($q2);
$newparent=$r2['parent'];
$parentname=$r2['name'];
$newpath="$parentname > ";
$path="$newpath$path";
return $path;
}
else
{
$path="";
return $path;
}
}
}


not tested yet, but i think it should be ok....



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum