Jump to content

categories


ttt

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.