klepec Posted June 17, 2012 Share Posted June 17, 2012 I have two databases, lets name them database ONE and database TWO. Every database record has an id of its author (user). There are no limits for records per user. I would like to run a statistics page for each user. For example, when John logs in: John | 20 of A (list) | 150 of B (list) demo code: $a = mysql_query("SELECT * FROM A WHERE userID='$userID'"); $b = mysql_query("SELECT * FROM B WHERE userID='$userID'"); $a_num=mysql_num_rows($a); $b_num=mysql_num_rows($b); $echo "$userID | $a_num of A <a href='/a/$userID'>(list)</a> | $b_num of B <a href='/b/$userID'>(list)</a> "; So, is check for number of records an optimal solution when number of database records come to few hundred or maybe thousand? Is there any better way to run statistics? Maybe a separate database which counts records for each user? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/264332-mysql-search-speed/ Share on other sites More sharing options...
Pikachu2000 Posted June 17, 2012 Share Posted June 17, 2012 Don't select data you aren't going to use. Use COUNT(). Quote Link to comment https://forums.phpfreaks.com/topic/264332-mysql-search-speed/#findComment-1354606 Share on other sites More sharing options...
litebearer Posted June 17, 2012 Share Posted June 17, 2012 http://www.tizag.com/mysqlTutorial/mysqlcount.php Quote Link to comment https://forums.phpfreaks.com/topic/264332-mysql-search-speed/#findComment-1354609 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.