this is my database structure for my terms table (categories):
id | name | parent_id | level | position
--------------------------------------------------------------
1 | term 1 | NULL | 0 | 1
2 | term 2 | 1 | 1 | 1
3 | term 3 | 1 | 1 | 2
4 | term 4 | NULL | 0 | 2
5 | term 5 | 4 | 1 | 1
so terms 2 and 3 are 1st level children of 1 and 5 is a first lst level child of 4
this is my query: (and it's not correct, this should be fixed)
SELECT
`id`,
`name`
FROM
`terms`
ORDER BY
`position` ASC,
`level` ASC
this is my php:
$terms = array();
// query part
if(!$this->_db->resultRows > 0)
return $terms;
while($d = $this->_db->fetch($r))
{
$terms[$d->id] = new Term($d->id);
}
return $terms;
current result:
term 1
term 2
term 5
term 4
term 3
but the result should be:
term 1
term 2
term 3
term 4
term 5
I don't know how to alter the query to get the correct result
the goal is to output this in a (multiple) select box
I know how to do it with nested lists, but you can't nest a select