I finding trouble deciding what is the fastest way to count some specifc records from my tables filtered by a where statment here is my code, here are the queries:
$type_mo3ln_malk = mysql_num_rows(mysql_query("SELECT * FROM `tableshow` $weress AND mo3ln_type='malk'")); $type_mo3ln_mswg = mysql_num_rows(mysql_query("SELECT * FROM `tableshow` $weress AND mo3ln_type='mswg'")); $type_mo3ln_mktb = mysql_num_rows(mysql_query("SELECT * FROM `tableshow` $weress AND mo3ln_type='mktb'")); $type_mo3ln_wkeel = mysql_num_rows(mysql_query("SELECT * FROM `tableshow` $weress AND mo3ln_type='wkeel'")); $type_mo3ln_no = mysql_num_rows(mysql_query("SELECT * FROM `tableshow` $weress AND mo3ln_type='0'")); the function that do the count are the one which is predefined in php
I am thinking of using count() function but I am wondering if I could use Sum function for some specific rows only as Mr.Hates suggested here Get record counts for all tables in MySQL database
COUNT(), so it is possible that the aggregate will be faster than callingmysql_num_rows(). But that also depends on your table's indexing, size, and other factors.mysql_*functions in new code. They were removed from PHP 7.0.0 in 2015. Instead, use prepared statements via PDO or MySQLi. See Why shouldn't I use mysql_* functions in PHP? for more information.