Forum
16:01
29/07/2009
Many times the nested set model doesn't have a 'level' field. This can be calculated from just the 'lft' and 'rgt' fields although it does add overhead to the mySQL server. Hope this helps someone else. 🙂
This has been adapted from a technique used by Joe Celco and the amazing work he has done with nested sets...
$SQL = sprintf("
SELECT t1.id AS id, t1.title AS title, t1.lft AS lft, t1.rgt AS rgt, COUNT(t2.id) AS level
FROM my_table AS t1, my_table AS t2
WHERE (t1.lft BETWEEN t2.lft AND t2.rgt)
AND (t1.lft > %s AND t1.rgt < %s )
GROUP BY t1.id
HAVING (COUNT(t2.id)= %s )
ORDER BY t1.lft;"
, $n_lft
, $n_rgt
, $n_lvl );
Most Users Ever Online: 715
Currently Online:
28 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66