Jump to content

categories


ttt

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.