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. Quote Link to comment 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 Quote Link to comment 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- Quote Link to comment 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 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.