Question

I have a column in my MySQL database for deleted values are usually 0 or 1. Usually when doing searches I omit the deleted by doing something like "and deleted = "0"" but I cant figure out how to get this query below to omit my deleted column. any ideas would be appreciated thanks!

$query = "SELECT Status, COUNT(Status) FROM Assets GROUP BY Status"; 

$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result))
{
   echo "". $row['COUNT(Status)'] ." systems ". $row['Status'];
   echo ", ";
}
Was it helpful?

Solution

This should work:

$query = "SELECT Status, COUNT(Status) FROM Assets WHERE Assets.deleted = 0 GROUP BY Status"; 

Also, you should use mysqli or PDO rather than mysql (the php mysql library is obsolete).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top