Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Dzewka - ostatnie liscie
ganimedes
post 24.07.2005, 10:48:03
Post #1





Grupa: Zarejestrowani
Postów: 66
Pomógł: 0
Dołączył: 1.04.2004

Ostrzeżenie: (0%)
-----


Witam stoje przed problemem napisania skryptu ktory wyświetlałby "ostatnie liście" w drzewie kategorii. Kożystam z rozwiązania ktore jest na sitepoint http://www.sitepoint.com/article/hierarchical-data-database/
  1. <?php 
  2. function display_tree($root) { 
  3.  // retrieve the left and right value of the $root node 
  4.  $result = mysql_query('SELECT lft, rgt FROM tree '. 
  5. 'WHERE title=\"'.$root.'\";'); 
  6.  $row = mysql_fetch_array($result); 
  7.  
  8.  // start with an empty $right stack 
  9.  $right = array(); 
  10.  
  11.  // now, retrieve all descendants of the $root node 
  12.  $result = mysql_query('SELECT title, lft, rgt FROM tree '. 
  13. 'WHERE lft BETWEEN '.$row['lft'].' AND '. 
  14. $row['rgt'].' ORDER BY lft ASC;'); 
  15.  
  16.  // display each row 
  17.  while ($row = mysql_fetch_array($result)) { 
  18.  // only check stack if there is one 
  19.  if (count($right)>0) { 
  20.  // check if we should remove a node from the stack 
  21.  while ($right[count($right)-1]<$row['rgt']) { 
  22.  array_pop($right); 
  23.  } 
  24.  } 
  25.  
  26.  // display indented node title 
  27.  echo str_repeat(' ',count($right)).$row['title'].&#092;"n\"; 
  28.  
  29.  // add this node to the stack 
  30.  $right[] = $row['rgt']; 
  31.  } 
  32. } 
  33. ?>

Podaje ID rodzica np Food i chce zeby wyświetliło mi ostatnie liście czyli Cheery, Banana, Beef, Pork

Siedze przy tym juz pare godzin i nie moge wpaść na pomysł, kto może ma?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 15:30