gurpreet Posted January 2, 2009 Posted January 2, 2009 OK so I'm tryna add referals in HOF. I got this from the Viewuser: $rr=$db->query("SELECT * FROM referals WHERE refREFER={$r['userid']}"); I want to make it just like HOF level and stuff, but for referals. $q=$db->query("SELECT u.*,g.* FROM users u LEFT JOIN gangs g ON g.gangID=u.gang WHERE u.user_level != 0 AND u.user_level != 2 $myf ORDER BY referals DESC,userid ASC LIMIT 20"); That doesn't work. I need it to get info from 2 tables but in 1 query...Help would be good :) Quote
Karlos Posted January 2, 2009 Posted January 2, 2009 Re: Referal in HOF 2 Tables? 1 Query? .... LEFT JOIN ? Quote
gurpreet Posted January 2, 2009 Author Posted January 2, 2009 Re: Referal in HOF I dunno..I got that bit from the original halloffame but I need to edit it. Quote
gurpreet Posted January 2, 2009 Author Posted January 2, 2009 Re: Referal in HOF $refwin = mysql_query("SELECT * FROM referals WHERE refREFER={$r['userid']}"); {echo '$refwin';} When I do that, it echos "$refwin" not the database info. Any ideas? Quote
BlueDevil23 Posted January 2, 2009 Posted January 2, 2009 Re: Referal in HOF $refwin = mysql_query("SELECT * FROM referals WHERE refREFER={$r['userid']}"); {echo '$refwin';} When I do that, it echos "$refwin" not the database info. Any ideas? print "$refwin"; Quote
POG1 Posted January 2, 2009 Posted January 2, 2009 Re: Referal in HOF $refwin = mysql_query("SELECT * FROM referals WHERE refREFER={$r['userid']}"); {echo '$refwin';} When I do that, it echos "$refwin" not the database info. Any ideas? print "$refwin"; its still gona be the same lol You need.. $refwin = mysql_num_rows(mysql_query("SELECT * FROM referals WHERE refREFER={$r['userid']}")); Quote
gurpreet Posted January 2, 2009 Author Posted January 2, 2009 Re: Referal in HOF Pog1: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/*******/public_html/competition.php on line 3 $refwin = mysql_num_rows(mysql_query("SELECT * FROM referals WHERE refREFER={$r['userid']}")); is line 3 Quote
Magictallguy Posted January 3, 2009 Posted January 3, 2009 Re: Referal in HOF $sql = sprintf("SELECT * FROM referals WHERE (refREFER = %u)", $r['userid']); $query = mysql_query($sql) or die(mysql_error()); $refwin = mysql_num_rows($query); Quote
BlueDevil23 Posted January 3, 2009 Posted January 3, 2009 Re: Referal in HOF $refwin = mysql_query("SELECT * FROM referals WHERE refREFER={$r['userid']}"); {echo '$refwin';} When I do that, it echos "$refwin" not the database info. Any ideas? print "$refwin"; its still gona be the same lol You need.. $refwin = mysql_num_rows(mysql_query("SELECT * FROM referals WHERE refREFER={$r['userid']}")); Lol, I didn't take a look at the code, and assumed he had it right, just glanced at the echo and noticed the single quotes :P Quote
gurpreet Posted January 3, 2009 Author Posted January 3, 2009 Re: Referal in HOF Doesn't print anything, here's my code so far, I know it shows the ranks by level, need to set that to rank by referals later. Reason there are so much errors is because I was tryin to code by myself, seems I'm not ready for this stuff yet. <?php include "globals.php"; $sql = sprintf("SELECT * FROM referals WHERE (refREFER = %u)", $r['userid']); $query = mysql_query($sql) or die(mysql_error()); $refwin = mysql_num_rows($query); echo '<h4>Competitions!</h4> '; echo '<font size=5>MESSED UP ATM, SHOWING HIGHEST TO LOWEST LEVEL</font>'; print "$refwin"; echo '<h2>Current Competitions:</h2> '; print "Referal competition. <table width=75% cellspacing=1 class='table'> <tr> <td>[url='competition.php?action=referal']REFERALS[/url]</td></tr></table>"; switch($_GET['action']) { case "referal": hof_ref(); break; } function hof_ref() { global $db,$ir,$c,$userid, $myf; print "Showing the 20 users with the highest number of referals. <table width=75% cellspacing=1 class='table'><tr style='background:gray'> <th><font color=grey>Pos</font></th> <th><font color=grey>User</font></th> <th><font color=grey>Level</font></th></tr>"; $q=$db->query("SELECT u.*,g.* FROM users u LEFT JOIN gangs g ON g.gangID=u.gang WHERE u.user_level != 0 AND u.user_level != 2 $myf ORDER BY level DESC,userid ASC LIMIT 20"); $p=0; while($r=$db->fetch_row($q)) { $p++; if($r['userid'] == $userid) { $t="[b]";$et="[/b]"; } else { $t="";$et=""; } print "<tr> <td>$t$p$et</td> <td>$t{$r['gangPREF']} {$r['username']} [{$r['userid']}]$et</td> <td>$t{$r['level']}$et</td> </tr>"; } print "</table>"; } Special thanks to Dazza as he helped me with a lot of it. Quote
POG1 Posted January 3, 2009 Posted January 3, 2009 Re: Referal in HOF $refwin = mysql_query("SELECT * FROM referals WHERE refREFER={$r['userid']}"); {echo '$refwin';} When I do that, it echos "$refwin" not the database info. Any ideas? print "$refwin"; its still gona be the same lol You need.. $refwin = mysql_num_rows(mysql_query("SELECT * FROM referals WHERE refREFER={$r['userid']}")); Lol, I didn't take a look at the code, and assumed he had it right, just glanced at the echo and noticed the single quotes :P But in that case your still gonna try and print a query, not really gonna work. Quote
p_T_s Posted January 6, 2009 Posted January 6, 2009 Re: Referal in HOF Has anyone got a working "referals" in the HOF? I have been trying to add this and it just dont work.... A huge thx inadvance if someone can help me out? Quote
p_T_s Posted January 7, 2009 Posted January 7, 2009 Re: Referal in HOF Ok maybe if i post what i have so far, someone can help fill in the gaps? <td>[url='halloffame.php?action=referals&filter={$filter}']REFERALS[/url]</td> case "referals": hof_referals(); break; function hof_referals() { global $db,$ir,$c,$userid; print "Showing the top 20 Referers <table width=75% cellspacing=1 class='table'><tr style='background:gray'> <th>Pos</th> <th>User</th> <th>Referals</th> </tr>"; $q=$db->query("SELECT * FROM referals ORDER BY refREFER DESC,refREFED ASC LIMIT 20"); $p=0; while($r=$db->fetch_row($q)) { $p++; if($r['userid'] == $ir['userid']) { $t="[b]";$et="[/b]"; } else { $t="";$et=""; } print "<tr> <td>$t$p$et</td> <td>$t{$r['refREFER']} {$r['username']} [{$r['userid']}]$et</td> <td>$t".money_formatter($r['referals'],'')."$et</td> </tr>"; } print "</table>"; } It looks like this in the Hall Of Fame Pos User Referals 1 4 [] 0 2 1 [] 0 So i have the users id's but no username showing and not showing how many referals??? Quote
POG1 Posted January 7, 2009 Posted January 7, 2009 Re: Referal in HOF the query is selecting from the referals table and the username is in the users table. Take a look at LEFT JOIN in the mysql manual.. Quote
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.