8 years ago
Topic

Hi, I have some code from another post on this forum in order to display child elements in a Dynamic Select field:

SELECT CONCAT( REPEAT('-', (category.level)-1), category.title) AS text, category.id AS value 
FROM #__categories AS category
LEFT JOIN #__categories AS parent ON category.lft BETWEEN parent.lft AND parent.rgt
WHERE parent.id = 115 ORDER BY category.lft

This almost gives me what I'm looking for so the select field displays like this (note the dash on sub options):

Option 1
Option 2
-Sub Option 1
-Sub Option 2
Option 3
Option 4

Unfortunately it displays the Parent category at the top which I don't want. I can't quite get my head round the SQL code so could anyone give me some help as to how I show all the children, in hierarchical order but not display the top level parent, please?

Get a Book for SEBLOD
4229 Posts
Kadministrator
8 years ago
1
Level 1

So you don't want to display level 1 categories at all or just when there are child categories? Second one will be hard...

8 years ago
0
Level 2

Hi Klas

Sorry, I figured this out over the weekend:

Adding

AND parent.level >= 2

after

WHERE parent.id = 115

Ensured that only the Level 2 and above categories appeared. Getting the ordering I want means making sure I order the categories correctly in Joomla backend.

Get a VIP membership