1,105,578 Community Members

Returns only 1 record from mysql database..:(

Member Avatar
codewalkz
Junior Poster in Training
51 posts since Nov 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
-1
 
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$root = 1;
function display_tree($root) {
   // retrieve the left and right value of the $root node

   $result = mysql_query('SELECT lft, rgt FROM tree '.
                          'WHERE name="'.$root.'";');
   $row = mysql_fetch_array($result);

   // start with an empty $right stack
   $right = array();

   // now, retrieve all descendants of the $root node
   $result = mysql_query('SELECT COUNT(*), upline, name, lft, rgt FROM tree '.
                          'WHERE lft BETWEEN '.$row['lft'].' AND '.
                          $row['rgt'].' ORDER BY lft ASC;');

   // display each row
   while ($row = mysql_fetch_array($result)) {
      $counts = "".$row['COUNT(*)']."";
       // only check stack if there is one
       if (count($right)>0) {
           // check if we should remove a node from the stack
           while ($right[count($right)-1]<$row['rgt']) {
               array_pop($right);
           }
       }

       // display indented node name
       echo str_repeat('  ',count($right)).$row['name']."\n";

       // add this node to the stack
       $right[] = $row['rgt'];
   }
}

echo "".$row['name']." $counts ";
Member Avatar
sam023
Junior Poster
164 posts since Jun 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

this is may be because of Query u used..!!

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

count return 1 result..

delete count(*) from query and use mysql_num_rows($result) for row count

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: