ttt Posted October 14, 2007 Share Posted October 14, 2007 hi! i have mysql table named "categories" with fields: id parent_id label and problem is. How can i print out categories like: id parent_id parent_id parent_id id parent_id parent_id id id parent_id Sorry form my english. thx Link to comment https://forums.phpfreaks.com/topic/73180-categories/ Share on other sites More sharing options...
jorgep Posted October 15, 2007 Share Posted October 15, 2007 You are not making your self clear enough... As I could guess, you can have datas inc ategories like: id parent_id label 1 2 asdasa 1 3 asdasd 1 1 aljhfsa If thats right... you could do it like this: $qGetIds = "SELECT id FROM categories ORDER BY id"; $rIds = mysql_query($qGetIds); if($rIds && mysql_num_rows($rIds) > 0){ while($dIds = mysql_fetch_assoc($rIds)){ $qGetParents = "SELECT parent_id FROM categories WHERE id='"+$dIds['id']+"'"; $rParents = mysql_query($qGetParents); echo $dIds['id']."<br />"; if($rParents && mysql_num_rows($rParents) > 0){ while($dParents = mysql_fetch_assoc($rParents)){ echo $dParents['parent_id']."<br />"; } } } } May be you should think of make a better structure of your database or give us more information about what your are trying to do... Hope this helps Link to comment https://forums.phpfreaks.com/topic/73180-categories/#findComment-369691 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.