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