# How to calculate the same number of values in the column mySQL and display in PHP?

Good afternoon. Have a table of clients. It has columns email, name, date.
I want to count how many I have in the email column values bill@microsoft.com and output in the php script the number of repetitions.
How to do it ? Please tell me. Many thanks in advance!
March 19th 20 at 09:02
March 19th 20 at 09:04
Solution
SELECT COUNT(email) AS emails FROM clients WHERE email = 'bill@microsoft.com';
do this:
$co = mysql_query("SELECT COUNT(email) AS emails FROM clients WHERE email = 'bill@microsoft.com';");$count = mysql_num_rows($co); echo$count;

Displays 1, even though records are actually 3 of these. num_rows in the cycle have to get or how to do it properly?
thank you. - Maggie commented on March 19th 20 at 09:07
@Maggie, well, well, the response contains 1 row - Loyce68 commented on March 19th 20 at 09:10
for the future. the function mysql_query in PHP does not exist. so you can expect very unpleasant surprises - Jaycee84 commented on March 19th 20 at 09:13
@Maggie,
$sql ="SELECT COUNT(email) AS emails FROM clients WHERE email = 'bill@microsoft.com'";$result = mysqli_query($link,$sql) or print(mysqli_error($link));$data = mysqli_fetch_array($result); echo$data['emails'];
- Loyce68 commented on March 19th 20 at 09:16
@Loyce68, but the same values bill@microsoft.com column email = 3. Why is it 1 ? :) - Maggie commented on March 19th 20 at 09:19
@Maggie,

$co = mysql_query("SELECT COUNT(email) AS emails FROM clients WHERE email = 'bill@microsoft.com';");$count = mysql_num_rows($co); echo$count;

so if you want, then SELECT email FROM.... - Loyce68 commented on March 19th 20 at 09:22
@Maggie,
Why is it 1 ? :)

well, now you understand why
- Loyce68 commented on March 19th 20 at 09:25
@Maggie, because the function count() aggregate. - Jaycee84 commented on March 19th 20 at 09:28
@Loyce68, thanks, did just that. - Maggie commented on March 19th 20 at 09:31
March 19th 20 at 09:06
$pdo=new PDO(here is your data for connecting to database);$result=$pdo->prepare("SELECT count(email) as cnt FROM clients WHERE email=:email GROUP BY email");$result->execute(array(":email" => "bill@microsoft.com"));
print $result->rowCount(); $pdo=new PDO("mysql:dbname=test;host=localhost", "root", "");
$result=$pdo->prepare("SELECT count(email) as cnt FROM clients WHERE email=:email GROUP BY email");
$result->execute(array(":email" => "bill@microsoft.com"));$row= $result->fetchAll(PDO::FETCH_ASSOC); pritn$row[0]['cnt'];

either way:
$pdo=new PDO("mysql:dbname=test;host=localhost", "root", "");$result=$pdo->prepare("SELECT 1 FROM clients WHERE email=:email");$result->execute(array(":email" => "bill@microsoft.com"));
print $result->rowCount(); the second and quadruple lines wrong - Jaycee84 commented on March 19th 20 at 09:09 @Jaycee84, second right, past the jamb. $pdo=new PDO("mysql:dbname=test;host=localhost", "root", "");
$result=$pdo->prepare("SELECT count(email) as cnt FROM clients WHERE email=:email GROUP BY email");
$result->execute(array(":email" => "bill@microsoft.com"));$row= $result->fetchAll(PDO::FETCH_ASSOC); pritn$row[0]['cnt'];

either way:
$pdo=new PDO("mysql:dbname=test;host=localhost", "root", "");$result=$pdo->prepare("SELECT 1 FROM clients WHERE email=:email");$result->execute(array(":email" => "bill@microsoft.com"));
print \$result->rowCount();
- Heber52 commented on March 19th 20 at 09:12
OMFG, fetchAll. Other methods to pdostatement not found? only a two-dimensional array to pull to get a single scalar value?
well, try to explain me why this query GROUP BY - Jaycee84 commented on March 19th 20 at 09:15
thanks for the help! solved the problem. - Maggie commented on March 19th 20 at 09:18

Find more questions by tags MySQLPHP