Gotharious Posted November 5, 2011 Share Posted November 5, 2011 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/250522-multiplying-variables/ Share on other sites More sharing options...
Gotharious Posted November 5, 2011 Author Share Posted November 5, 2011 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; Quote Link to comment https://forums.phpfreaks.com/topic/250522-multiplying-variables/#findComment-1285337 Share on other sites More sharing options...
trq Posted November 6, 2011 Share Posted November 6, 2011 This would be allot simpler if you where using some form of hierarchal data structure as previously suggested. Quote Link to comment https://forums.phpfreaks.com/topic/250522-multiplying-variables/#findComment-1285379 Share on other sites More sharing options...
Gotharious Posted November 6, 2011 Author Share Posted November 6, 2011 I've tried, mate I thought it was working, but I clearly had no idea what I was doing, and didn't give me different results than I'm having now, so I thought about taking the cave man approach I'm not that experienced tho Quote Link to comment https://forums.phpfreaks.com/topic/250522-multiplying-variables/#findComment-1285383 Share on other sites More sharing options...
seany123 Posted November 6, 2011 Share Posted November 6, 2011 the error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource is saying the the mysql query didnt return any results... do does the table have rows which are connected via recruiteris / recruitis? Quote Link to comment https://forums.phpfreaks.com/topic/250522-multiplying-variables/#findComment-1285631 Share on other sites More sharing options...
haku Posted November 6, 2011 Share Posted November 6, 2011 Actually it means that the query was invalid. An empty result won't give that error. Quote Link to comment https://forums.phpfreaks.com/topic/250522-multiplying-variables/#findComment-1285638 Share on other sites More sharing options...
Gotharious Posted November 6, 2011 Author Share Posted November 6, 2011 Oh.... it's recruiteris not recruitis is that what's giving the error? Quote Link to comment https://forums.phpfreaks.com/topic/250522-multiplying-variables/#findComment-1285649 Share on other sites More sharing options...
seany123 Posted November 6, 2011 Share Posted November 6, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/250522-multiplying-variables/#findComment-1285650 Share on other sites More sharing options...
Gotharious Posted November 6, 2011 Author Share Posted November 6, 2011 Ok thanks, Sean. How you think is the best way to make that kind of multiple queries? hence they are all on the same table tho Quote Link to comment https://forums.phpfreaks.com/topic/250522-multiplying-variables/#findComment-1285653 Share on other sites More sharing options...
seany123 Posted November 6, 2011 Share Posted November 6, 2011 well you could add a value in the table called "done" int 1 (default 0) and then select from users where done = 0 the once the queries are complete, you can update the row['done'] to 1 Quote Link to comment https://forums.phpfreaks.com/topic/250522-multiplying-variables/#findComment-1285655 Share on other sites More sharing options...
xyph Posted November 6, 2011 Share Posted November 6, 2011 This article explains most of what you need to know about hierarchical data (parent->child relationships) in MySQL http://explainextended.com/2009/03/17/hierarchical-queries-in-mysql/ Quote Link to comment https://forums.phpfreaks.com/topic/250522-multiplying-variables/#findComment-1285658 Share on other sites More sharing options...
Gotharious Posted November 6, 2011 Author Share Posted November 6, 2011 Thanks, guys you've been a great help Quote Link to comment https://forums.phpfreaks.com/topic/250522-multiplying-variables/#findComment-1285662 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.