I'm am brand new to php and just found this forum this morning. I spent five hours yesterday trying to figure out how to count values in a column, but thanks to a post here I have now figured out how.
However, the way I coded it seems a bit long.
The column values are Y, N and null. I want to find out how many members (Y) and how many non-members I have on my site (N, null). The code works with the results below, but is there a shorter way to code it?
RESULTS:
There are 5000 members.
There are 20000 non-members.
There are 25000 total users.
CODE:
$con = mysql_connect("localhost", "xxxxxxxxxx", "xxxxxxxxxx")
or die(mysql_error());
mysql_select_db("xxxxxxxxxx") or die(mysql_error());
$result = mysql_query("SELECT activate, COUNT(activate) FROM
customers WHERE activate='y'");
// Print out result
while($row = mysql_fetch_array($result))
{
echo "There are ". $row['COUNT(activate)'] ." members.";
echo "<br />";
}
mysql_close($con);
$con = mysql_connect("localhost", "xxxxxxxxxx", "xxxxxxxxxx")
or die(mysql_error());
mysql_select_db("xxxxxxxxxx") or die(mysql_error());
$result = mysql_query("SELECT activate, COUNT(activate) FROM
customers WHERE activate!='y'");
// Print out result
while($row = mysql_fetch_array($result))
{
echo "There are ". $row['COUNT(activate)'] ." non-members.";
echo "<br />";
}
mysql_close($con);
$con = mysql_connect("localhost", "xxxxxxxxxx", "xxxxxxxxxx")
or die(mysql_error());
mysql_select_db("xxxxxxxxxx") or die(mysql_error());
$result = mysql_query("SELECT activate, COUNT(activate) FROM
customers WHERE activate!='0'");
// Print out result
while($row = mysql_fetch_array($result))
{
echo "There are ". $row['COUNT(activate)'] ." total users.";
echo "<br />";
}
mysql_close($con);