My database looks like (pligg cms, sample data)
id catID parentID catName
1 1 0 location
2 2 0 color
3 3 1 US
Based on @GWW answer
function getLocationArray($start){
$link=dbConnect();//a function returning the link with your db
$stack = array();
$parent = $start;
while($parent != 0){
$query='SELECT catName,parentID from myTable where catId='.$parent;
$result = mysql_query($query,$link);
while($row = mysql_fetch_assoc($result)){
$parent=$row['parentID'];
$name=$row['catName'];
$stack[] = $name;
/*foreach($row as $cname => $cvalue){
}*/
}
}
$stack = array_reverse($stack);
return $stack;
}
var_dump($stack);