stelthius Posted May 24, 2009 Share Posted May 24, 2009 Hey guys just a quick one to see if any one has any tips on cleaning this up, $query = mysql_query("SELECT u.username FROM ".TBL_USERS." u INNER JOIN ".TBL_ACTIVE_USERS." a ON a.username=u.username WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND u.username= '" . $value[$x]['username'] . "'")or die(mysql_error()); if (mysql_num_rows($query) > 0) // Check to see if person is Online $status = "<img src=\"images/online.gif\"><br />"; else $status = "<img src=\"images/offline.gif\"><br />"; Basicly just use it to tell me when a user(s) is on/offline but i feel its not as clean as it could be any tips appretiated. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 24, 2009 Share Posted May 24, 2009 Based on this - $value[$x]['username'] you have the posted code inside of a loop. It is extremely inefficient to execute a query in a loop to retrieve a set of same type values. You should form a query that retrieves all the matching rows in a single query and then loop through the result set. Look at the mysql IN() function to get all the u.username's that are in your $value array in one query - http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_in Quote Link to comment Share on other sites More sharing options...
stelthius Posted May 24, 2009 Author Share Posted May 24, 2009 Ok thanks for the advice PFM, one last question ive looked on google for some tutorials or guides on combining two queries but i cant find anything that looks correct.. has anyone got any advice or tutorials they could link me please so i can learn how to do this properly and efficiantly Quote Link to comment 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.