-1

i'm trying to figure out how to use the MPTTD using sitepoint's tutorial.

$result = mysql_query('SELECT title, lft, rgt FROM tree '.  
'WHERE lft BETWEEN '.$row['lft'].' AND '.  
$row['rgt'].' ORDER BY lft ASC;');

the root has lft = 1, rgt = 42 so if i used lft = 1, rgt = 42 .. it would return

A A1 A2 A3 A4 B B1 B2 B3 B4 C C1 C2 C3 C4 D D1 D2 D3 D4

how do i retrieve only the 1st and 2nd child from the descendants like this

A A1 A2 B B1 B2 C C1 C2 D D1 D2

thank you for your help :)

1 Answers1

0

You have two options. Option 1: First get the left and right value. Then use left and right value. Select * from table where left=2 and right=17. Option 2: To get each descendants you can use the left value and any number of children for example where left=2 between left+2. For example:

   $result = mysql_query('SELECT title, lft, rgt FROM tree '.  
   'WHERE lft BETWEEN '.$row['lft'].' AND '. $row['lft']+2.' ORDER BY lft ASC;');
Micromega
  • 12,486
  • 7
  • 35
  • 72