Jump to content

Recommended Posts

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 :)

Link to comment
https://forums.phpfreaks.com/topic/86152-sql-count/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/86152-sql-count/#findComment-440028
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.