Jump to content

how to display 2 query results not just one


Gotharious
 Share

Recommended Posts

Hello all,

 

I have made the multi level marketing downline tree, but the problem with it now, it gives only the downline of one result, as the query gives 2 results

what I want now is to make it give the downline of both results not just one, and it's always 2 results, not more

 

here is my code

 


<?php

$id = $_GET['id'];     $result = mysql_query("SELECT id FROM users WHERE id = '".$id."' ORDER BY id");    $row = mysql_fetch_assoc($result);   if ($row['id'] == 0) {        echo"
<table>
<div id=\".piccenter\"";    
echo "<tr>";
echo "<img src=\"icon.gif\" border=0 align=\"center\">"; echo ""; } else {  echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$row['id']."'"; echo ""; echo "</div>";  }  }    $result2 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$row['id']."'");    $rows2 = mysql_fetch_assoc($result2);  foreach ($rows2 as $row2) { if ($row2['id'] == 0) {        echo" <div id=\".picleft\"> <img src=\"icon.gif\" border=0 align=\"center\">"; } else {  echo "<img src=\"images.png\" border=0 >"; echo "<br />"; echo "'".$row2['id']."'"; echo "</div>"; echo "

<td>";      echo "</td>


";  }  }   $result3 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows2['id']."'");    $row3 = mysql_fetch_assoc($result3);   if ($row3['id'] == 0) {        echo"<div id=\".picright\"> <img src=\"icon.gif\" border=0 align=\"center\">"; } else {  echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$row3['id']."'"; echo ""; echo "
<tr>
<td>";      echo "</td>
</tr>
";  }     $result4 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$row3['id']."'");    $rows4 = mysql_fetch_assoc($result4);   if ($rows4['id'] == 0) {        echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else {  echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows4['id']."'"; echo ""; echo "

<tr>
<td>";     echo "</td>
</tr>
";    }   $result5 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows4['id']."'");    $rows5 = mysql_fetch_assoc($result5);   if ($rows5['id'] == 0) {        echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else {  echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows5['id']."'"; echo ""; echo "

<tr>
<td>";      echo "</td>
</tr>
";    }   $result6 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows5['id']."'");    $rows6 = mysql_fetch_assoc($result6);   if ($rows6['id'] == 0) {        echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else {  echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows6['id']."'"; echo ""; echo "

<tr>
<td>";      echo "</td>
</tr>

";    }   $result7 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows6['id']."'");    $rows7 = mysql_fetch_assoc($result7);   if ($rows7['id'] == 0) {        echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else {  echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows7['id']."'"; echo ""; echo "

<tr>
<td>";     echo "</td>
</tr>

";    }   $result8 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows7['id']."'");    $rows8 = mysql_fetch_assoc($result8);   if ($rows8['id'] == 0) {        echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else {  echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows8['id']."'"; echo ""; echo "

<tr>
<td>";      echo "</td>
</tr>
";    }   $result9 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows8['id']."'");    $rows9 = mysql_fetch_assoc($result9);   if ($rows9['id'] == 0) {        echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else {  echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows9['id']."'"; echo ""; echo "

<tr>
<td>";     echo "</td>
</tr>
</tbody>
</table>
";  }    ?>

Link to comment
Share on other sites

I tried that, but I got no results

 

that was the code

 

       <?php 

       $root = $_GET['id'];
function display_tree($root) {  
    // retrieve the left and right value of the $root node  <br>
    $result = mysql_query('SELECT lft, rgt FROM users '.  
                           'WHERE recruiteris="'.$root.'";');  
    $row = mysql_fetch_array($result);  
  
    // start with an empty $right stack  <br>
    $right = array();  
  
    // now, retrieve all descendants of the $root node  <br>
    $result = mysql_query('SELECT recruiteris, lft, rgt FROM users '. 
                           'WHERE lft BETWEEN '.$row['lft'].' AND '. 
                           $row['rgt'].' ORDER BY lft ASC;');  
    // display each row  <br>
    while ($row = mysql_fetch_array($result)) { 
        // only check stack if there is one  <br>
        if (count($right)>0) { 
            // check if we should remove a node from the stack  <br>
            while ($right[count($right)-1]<$row['rgt']) { 
                array_pop($right);  
            }  
        }  
  
        // display indented node title  <br>
        echo str_repeat('  ',count($right)).$row['recruiteris']."\n";  
        echo $row['id'];
        // add this node to the stack  <br>
        $right[] = $row['rgt'];  
    }  
}  
?>

Link to comment
Share on other sites

Ok, I finally got this to work now

but now I want to make it appear in an organizational structure, something like Google's chart

http://code.google.com/apis/chart/interactive/docs/gallery/orgchart.html

 

Here is my code, how can I make this work?

<?
$user = $_GET['id'];
echo '<hr>'; 
function display_mptt($user) {
global $db;
// retrieve the left and right value of the $root node
$sql2 = "SELECT * from mptt where id= ".$user."";

$result2 = mysql_query($sql2 ,$db);
if(!$row2 = mysql_fetch_array($result2)) echo mysql_error();
echo '<h1>Your Tree</h1>';

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

// now, retrieve all descendants of the $root node
  $sql = "SELECT * from mptt WHERE `left` BETWEEN ".$row2['left']." AND ".$row2['right']." ORDER BY 'left' ASC";
$result = mysql_query($sql ,$db);

// display each row
  while ($row = mysql_fetch_array($result)) {
  // 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['right']) {
  array_pop($right);
  }
  }
// display indented node title
  echo str_repeat('            ',count($right)).$row['title']."<br>";
// add this node to the stack
  $right[] = $row['right'];
  }
} 
  
  display_mptt(1);
?>

Link to comment
Share on other sites

Ok, Perhaps my last post should have been in Client Side forums, but that recursion worked

 

here is it's code for reference

 

<?
$user = $_GET['id'];
echo '<hr>'; 
function display_mptt($user) {
global $db;
// retrieve the left and right value of the $root node
$sql2 = "SELECT * from mptt where id= ".$user."";

$result2 = mysql_query($sql2 ,$db);
if(!$row2 = mysql_fetch_array($result2)) echo mysql_error();
echo '<h1>Your Tree</h1>';

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

// now, retrieve all descendants of the $root node
  $sql = "SELECT * from mptt WHERE `left` BETWEEN ".$row2['left']." AND ".$row2['right']." ORDER BY 'left' ASC";
$result = mysql_query($sql ,$db);

// display each row
  while ($row = mysql_fetch_array($result)) {
  // 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['right']) {
  array_pop($right);
  }
  }
// display indented node title
  echo str_repeat('            ',count($right)).$row['title']."<br>";
// add this node to the stack
  $right[] = $row['right'];
  }
} 
  
  display_mptt(1);
?>

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.