erme Posted January 28, 2010 Share Posted January 28, 2010 How can I display the total records in an sql database for anything with the same entry for a specific field. Example, I have 300 entries all with a 'County' field of Essex .. I want to display the number 300. Link to comment https://forums.phpfreaks.com/topic/190112-display-total-records/ Share on other sites More sharing options...
Andy-H Posted January 28, 2010 Share Posted January 28, 2010 $query = "SELECT * FROM Table WHERE County = 'Essex' ORDER BY id DESC"; $result = mysql_query($query)or trigger_error("MySQL Error With Query 1", E_USER_WARNING); $num = mysql_num_rows($result); echo "<pre>\tThere are " . number_format($num) . " records in the County 'Essex'.\n</pre>"; mysql_num_rows Link to comment https://forums.phpfreaks.com/topic/190112-display-total-records/#findComment-1003097 Share on other sites More sharing options...
ChemicalBliss Posted January 28, 2010 Share Posted January 28, 2010 Im not stalking you andy i swear . But you can use a native mysql function to count the number of rows: SELECT count(*) FROM `table` WHERE `County`='Essex' eg: <?php // Connect $query = "SELECT count(*) FROM `table` WHERE `County`='Essex'"; $result = mysql_query($query) or die(mysql_error()); $number = mysql_result($result,0,0); echo($number); ?> -CB- Link to comment https://forums.phpfreaks.com/topic/190112-display-total-records/#findComment-1003141 Share on other sites More sharing options...
Andy-H Posted January 28, 2010 Share Posted January 28, 2010 Im not stalking you andy i swear . lol Link to comment https://forums.phpfreaks.com/topic/190112-display-total-records/#findComment-1003225 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.