April 3, 2012

How can I echo a COUNT query

Question by Tom Gillespie

I’m new to mySQL and as such am just looking for a very simple COUNT query which I haven’t found explained online with any real clarity.

What I’m looking to do is

COUNT the number of rows in my PASSENGER table where groupID = 0, and then be able to echo the numerical value that the count will return, how can I do this?

Answer by Starx

Something like this

$query = "SELECT COUNT(*) c FROM PASSENGER WHERE groupID = 0;";
$result = mysql_query($query);
$row = mysql_fetch_assoc($query);
echo $row['c']; //Here is your count

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!