0
I have a category and subcategory structure. And I need to list all categories, and then their subcategories... But the listing went wrong. I’m using the codeigniter.
Structure of the Database:
SQL structure:
SELECT c1.*,
c2.id,
c2.id_categoria,
c2.categoria as nome_categoria
FROM categoria AS c1
LEFT JOIN categoria AS c2
ON c2.id_categoria = c1.id
How do I list all the categories and subcategories correctly? Within the same SQL, because I will recover the data by foreach() to display all categories and their subcategories. Today the result is like this:
The health category should also appear in the example...
@rray has any idea? :)
– Sr. André Baill
See if this fits your case http://explainextended.com/2009/03/17/hierarchical-queries-in-mysql/
– Lucas Fontes Gaspareto
It would serve yes, but could not adapt in this SQL
– Sr. André Baill
Why couldn’t I adapt ?
– Lucas Fontes Gaspareto
I couldn’t understand.. can post an example?
– Sr. André Baill
Andre see if this way it serves http://sqlfiddle.com/#! 2/2b5c3e/3. I’ll try the tutorial.
– Lucas Fontes Gaspareto
Let’s go continue this discussion in chat.
– Lucas Fontes Gaspareto