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
https://forums.phpfreaks.com/topic/250522-multiplying-variables/
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; 

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?

Archived

This topic is now archived and is closed to further replies.

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