Jump to content

only 3 queries are done, but not any more


Gotharious

Recommended Posts

Hello all,

 

I've tried several ways to calculate a commission in the multi level marketing script, but it all ended up with nothing, recursive functions, nested sets nothing worked, and i'm running out of time to keep trying

 

I've made multiple queries on the same table, and it's working, but only the first 3 queries, not more, I tried to perform it 4 times (although I need the queries to be performed 13 times) but still only 3 times

 

example: A recruited B and C, and B recruited D, and D recruited E.... what's supposed to happen is A takes a commission on B, C, D, and E

but now it only takes commission on the first three, and no commission for anyone comes after that, and the same for B, C, D, and E each takes commission on only 3 members down the line, and no more

 

here is the queries

 

<?
$result = mysql_query("SELECT * FROM users");


echo "<table width='589' border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>National ID</th>
<th>Commission</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  
$query = mysql_query("SELECT * from users where recruiteris = '".$row['id']."'");
$num_rows=mysql_num_rows($query);

              $id1 = $row['id'];  
                
                $commission = $num_rows;
                
                
            $_SESSION['id1'] = $id1;
                
  echo "<tr>";
  while ($roww = mysql_fetch_array($query))
  {
  $querry=mysql_query("select * from users where recruiteris = '".$roww['id']."'");
    $num_rowss = mysql_num_rows($querry);
  while ($rowws= mysql_fetch_array($querry))
   { $var3= '10';

  $querrys=mysql_query("select * from users where recruiteris = '".$rowws['id']."'");
    $num_rowsss = mysql_num_rows($querrys);
   while ($rowwss= mysql_fetch_array($querrys))
    
   {
    $querryss=mysql_query("select * from users where recruiteris = '".$rowwss['id']."'");
    $num_rowssss = mysql_num_rows($querryss);
   while ($rowwsss= mysql_fetch_array($querryss))
   {
    
    
    $querryr=mysql_query("select * from users where recruiteris = '".$rowwsss['id']."'");
    $num_rowssr = mysql_num_rows($querryr);
    }
    }
    }
    }
    $total= ($commission + $num_rowws + $num_rowwss + $num_rowwsss + $num_rowss + $num_rowssr) * $var3;
echo  "<td><a href=\"user.php?id=".$row['id']."\">".$row['id']."</a></td>";
echo "<td>" . $row['fname'] .''. $row['lname'] ." </td>";
echo"<td> ". $row['nid'] ." </td>";
  echo  "<td>".$total."</td>
   </tr>";
  }
  
echo "</table>";
        ?>  

Link to comment
Share on other sites

Ok, fixed that last part, but now having a very weird problem

some recruits are calculated and some aren't

 

I mean, there isn't like a pattern, not like only the first 5 calculated, or something, I mean sometimes it's the third person and the forth is calculated and sometimes it's the seventh and the eighth is calculated and so on, so I can't actually know what's wrong

 

here is the code

 

<?php


echo "<table width='589' border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>National ID</th>
<th>Commission</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  
$query = mysql_query("SELECT * from users where recruiteris = '".$row['id']."'");
$num_rows=mysql_num_rows($query);
$row1=mysql_fetch_array($query);
$result2 = mysql_query("SELECT * FROM users WHERE recruiteris = '".$row1['id']."'");
$num_rows1=mysql_num_rows($result2);
     $rows2 = mysql_fetch_array($result2);  
   $result3 = mysql_query("SELECT * FROM users WHERE recruiteris = '".$rows2['id']."'"); 
   $num_rows2=mysql_num_rows($result3);
      $row3 = mysql_fetch_array($result3);   
     $result4 = mysql_query("SELECT * FROM users WHERE recruiteris = '".$row3['id']."'");
     $num_rows3=mysql_num_rows($result4);
         $rows4 = mysql_fetch_array($result4); 
   $result5 = mysql_query("SELECT * FROM users WHERE recruiteris = '".$rows4['id']."'");
   $num_rows4=mysql_num_rows($result5);
       $rows5 = mysql_fetch_array($result5);   
  $result6 = mysql_query("SELECT * FROM users WHERE recruiteris = '".$rows5['id']."'");
  $num_rows5=mysql_num_rows($result6);
      $rows6 = mysql_fetch_array($result6);   
  $result7 = mysql_query("SELECT * FROM users WHERE recruiteris = '".$rows6['id']."'");
  $num_rows6=mysql_num_rows($result7);
      $rows7 = mysql_fetch_array($result7);   
   $result8 = mysql_query("SELECT * FROM users WHERE recruiteris = '".$rows7['id']."'");
   $num_rows7=mysql_num_rows($result8);
       $rows8 = mysql_fetch_array($result8);   

  $result9 = mysql_query("SELECT * FROM users WHERE recruiteris = '".$rows8['id']."'");
  $num_rows8=mysql_num_rows($result9);
      $rows9 = mysql_fetch_array($result9);   
$var3 = '10';
    
    $total= ($num_rows + $num_rows1 + $num_rows2 + $num_rows3 + $num_rows4 + $num_rows5 + $num_rows6 + $num_rows7 + $num_rows8) * $var3;
    $_SESSION['total'] = $total;
echo  "<td><a href=\"user.php?id=".$row['id']."\">".$row['id']."</a></td>";
echo "<td>" . $row['fname'] .''. $row['lname'] ." </td>";
echo"<td> ". $row['nid'] ." </td>";
  echo  "<td>".$total."</td>
   </tr>";
  }
  
echo "</table>";
        ?>  

Link to comment
Share on other sites

Ok, I solved this with the same pre-order recursion I used to display the MLM downline tree structure

 

I just made it instead of echoing the results of the recursion, to count the num of rows, subtract 1 then multiply by 10 which worked perfectly, as when counting the number of rows, it counts the row of the person I'm trying to find his commission out, so I had to remove it by subtracting one then mutliply it by 10 which is his commission for each person under him

 

here is the code

 

<?
$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
$commission =mysql_num_rows($result);
$var3= '10';
$total= ($commission - 1) * $var3;
echo $total;
// 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. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.