Suchy Posted July 17, 2009 Share Posted July 17, 2009 Which method causes less stress on the MySQL server. The SQL way: $query = "SELECT COUNT(person_id) AS counter FROM video WHERE person_id = 1 AND public_account = 1"; $result = mysql_query($query); $row = mysql_fetch_array($result); $counter = $row['counter']; or the PHP way: $query = "SELECT person_id FROM video WHERE person_id = 1 AND public_account = 1"; $result = mysql_query($query); $counter = mysql_num_rows($result); All I need is to display amount of videos each person has. Quote Link to comment https://forums.phpfreaks.com/topic/166382-sql-vs-php-count/ Share on other sites More sharing options...
kickstart Posted July 17, 2009 Share Posted July 17, 2009 Hi The SQL way should. If you want all the peoples counts then:- $query = "SELECT person_id, COUNT(person_id) AS counter FROM video WHERE public_account = 1 GROUP BY person_id"; All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/166382-sql-vs-php-count/#findComment-877407 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.