Tom Gillespie Tom Gillespie - 2 years ago 100
SQL Question

How can I echo a COUNT query

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 Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download