Jump to content

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


RJP1

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

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.