Counting rows (SOLVED)
Posted: Mon Nov 23, 2015 2:39 am
I know the subject is a little easy, however in my database I have a field called 'online' set to enum '0','1' and when they log out, it sets it as 0 and when they sign in, it sets it to one.
My question is, how do I count the rows in the database to ONLY count the ones set to 1? That way it can count how many people are currently online. I have one that counts the amount of registered users, but now I need it to count only the ones online. Here is the snipet of code that is supposed to count the rows that only have 1 listed.
My question is, how do I count the rows in the database to ONLY count the ones set to 1? That way it can count how many people are currently online. I have one that counts the amount of registered users, but now I need it to count only the ones online. Here is the snipet of code that is supposed to count the rows that only have 1 listed.
Code: Select all
<?php
$sql = mysql_query("SELECT COUNT(1) AS online FROM players");
$num1 = mysql_fetch_array($sql);
$counts = $num1['online'];
echo ("$counts");
if($counts == 0)
{
echo "0";
}
?>