Forum Moderators: coopster
So far I have got this
$result = mysql_query("SELECT * FROM categories WHERE id = '$id'") or die(mysql_error());
while($row = mysql_fetch_array( $result ))
{
$keyword = $row['keyword'];
$parent = $row['parent'];
}
So I want to do the above again and again .. until parent equals 0
Or are your entries like
ID----ParentID----Keyword
4----5------same
4----4------blue
4---3-------widgets
4----2-------sky
etc.
IF this is the case then add an ORDER BY after the WHERE. then use the
while($row=mysql_fetch_array($results)){}
Note: you will need to ORDER BY parent decending. I'm sure you can figure they way to do that.
Sarah
id parent title
1----5------sub category
2----5------sub category
3----5------sub category
4----5------sub category
5----0------main category
6----8------sub category
7----8------sub category
8----0------main category
9----7------sub sub category
So for each id I want to print out its main category, sub category, sub sub category etc etc, where parent 0 means main category. So for example I select id 9 and get sub category 7 now I have to do the same for sub cat 7 (as parent!=0) and so on until I reach 0 (main cat). I could keep doing individual querys as it wont be more than 5 deep, but I am sure there is a better way? I proberbly made it sound more confusing than it is :)