Jump to content

Best way to select categories, then subcategories and order as such?


Recommended Posts

Hi guys,

 

I'm building a category table in Joomla and have this so far:

 

id | name | parentid

-------------------------

1 | cat1    | 2

2 | cat2    | 0

3 | cat3    | 0

 

As you can see, categories 2 and 3 are parents (parentid = 0) but cat 1 is categorised under cat 1.

 

What is the best way to select subcategories straight after it's parent?

 

E.g.

cat2, cat1, cat3 to then go on to put them in a table.

 

Would it be best to prevent runaway categorisation and just allow categories and subcategories?

 

Cheers for the guidance.

 

RJP1

What I meant by runaway categorisation was:

 

Parent

  - child 1

    - child 1's child

        - etc

  - child 2

 

But I have figured out how to prevent this in my application, but I have yet to figure out how to get a list of parents then each parents child categories like so:

 

- parent

  - child

  - child

- parent

- parent

- parent

  - child

 

etc

 

I'll have a look at it now and see if I can figure it out, I managed the harder query in my other post you thought this was like. They are similar and I apologise for the seemingly double post.

 

Cheers,

 

RJP1

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.