avo Posted January 15, 2008 Share Posted January 15, 2008 Hi All How would i please count the number of times a coloum holds a specific (coloums hold the same value)value denoted by the where clause i thought it was like :- $query = "SELECT customer_name, COUNT(customer_name) FROM serials GROUP BY customer_name WHERE id='".$exploded[0]."' "; Help Appriciated Quote Link to comment https://forums.phpfreaks.com/topic/86152-sql-count/ Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 can't you just use mysql_count_row to see how many result are return back from the query? Quote Link to comment https://forums.phpfreaks.com/topic/86152-sql-count/#findComment-440006 Share on other sites More sharing options...
PFMaBiSmAd Posted January 15, 2008 Share Posted January 15, 2008 Because of the way you are referencing the customer_name in the query, the results will contain a row for each customer_name, followed by how many times that customer_name is in the result set. To just get a count of the rows, try this - $query = "SELECT COUNT(*) FROM serials WHERE id='".$exploded[0]."' "; adam291086, program execution is always quicker any time you can get the database to directly produce the answer. Using the COUNT() function in the query means that the database does not need to send all the rows in the result set to php, where php must use memory to store the result resource, just so that the rows can be counted using the mysql_num_rows() function. Quote Link to comment https://forums.phpfreaks.com/topic/86152-sql-count/#findComment-440028 Share on other sites More sharing options...
avo Posted January 15, 2008 Author Share Posted January 15, 2008 Just what i was after Thanks appreciated . Quote Link to comment https://forums.phpfreaks.com/topic/86152-sql-count/#findComment-440067 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.