Jump to content

multiplying variables


Gotharious

Recommended Posts

hello,

 

what I made is, each user joins in, he enters a recruitment ID of another user who recruited him, so I can calculate the commission of each.

and It's working great

but now what I want to do, is to make each user take comission of the people he recruited, and the people they recruited and so on

 

here is my code for the first, don't know how to make the second

 

<?php
$result = mysql_query("select * from users where id = '{$_GET['id']}'");




	$row = @mysql_fetch_array($result);
	$rid = $row['id'];
	$sql = mysql_query("select * from users where recruiteris = $rid");
                $num_rows = mysql_num_rows($sql);
                $var3 = '10';
                $commission = $num_rows * $var3; 
?>

Link to comment
Share on other sites

I tried making multiple queries on the same table but didn't work, kept giving me

 

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

 

what I tried was

 

<?php

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


while($row = mysql_fetch_array($result))
  {
  	  $rid = $row['id'];
	$sql = mysql_query("select * from users where recruiteris = $rid");
                $row2 = mysql_fetch_assoc($sql);
	$num_rows = mysql_num_rows($sql);
                $rid2 = $row2['id'];
	$sql2 = mysql_query("select * from users where recruitis = $rid2");
                $num_rows2 = mysql_num_rows($sql2);
	$total = $new_rows + $new_rows2;
                $var3 = '10';
                $commission = $total * $var3; 

Link to comment
Share on other sites

Also you have

 

$total = $new_rows + $new_rows2;

 

should it not be

 

$total = $num_rows + $num_rows2;

 

Secondly the While loop is doing absolutely no good because you are always going to be querying the same ID

 

if you gave more information what your wanting to do then i could help you further, why have you not put this information into its own table called recruits or something?

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.