I usually try avoiding loops, but this time I can't. <? $disabledusrs= mysql_query("SELECT username FROM $tab[user] WHERE receiveletter='no'"); while($pullthem = mysql_fetch_array($disabledusrs)){ // pulls top 3 players $gettop3 = mysql_query("SELECT * FROM $tab[topguys] WHERE username != '' AND username != '$pullthem[username]' ORDER BY win DESC, played DESC, lost ASC LIMIT 3"); $keyr = 1; $winner = array(); while($rowin = mysql_fetch_array($gettop3)){ $winner[$keyr] = $rowin; $keyr++; } } ?> PHP: It was working before, but then I added another loop (the first one) and tried to connect them... The point is that there are 2 tables. 1st one is users, second one is topguys. Both of the tables have data with the same usernames... I want gettop3 to pull only these usernames from table topguys where username != disabledusrs[username]. So it looks at one table and finds out where the user has receiveletter='no', then the other loop takes the username and skips all users with receiveletter='no'. I did my best explaining the issue.
You can use subquery SELECT * FROM $tab[topguys] WHERE username != '' AND username NOT IN(SELECT username FROM $tab[user] WHERE receiveletter='no') ORDER BY win DESC, played DESC, lost ASC LIMIT 3
I didn't know such thing existed! Oh boy, I've wasted so much time when I could just have used that trick. Thanks, I'm going to give it a try!
Okay, it works. THANK YOU. It takes about 3 seconds to load on my local server to open up the page. Is that normal?
OK, I think I definitely need a new solution. it takes about 20 seconds to load on the production server... Plus the queries are probably killing the server. Any ideas guys?