I have a query as follows, I get the response and for some reason the while loop never catches the first group of status returned. If MySQL returned status I,S,N
it will only process the S
and N
. If it returns S,N
it will only process N
.
$sql = "SELECT COUNT(*) as cnt, status
FROM itemInterest
GROUP BY status
ORDER BY STATUS";
echo $sql;
$rs = mysql_query($sql);
while($row = mysql_fetch_array($rs))
{
echo $row['status'];
if($row['status'] == "N") {
$noResponse = $row['cnt'];
}
if($row['status'] == "S") {
$saved = $row['cnt'];
}
if($row['status'] == "I") {
$interested = $row['cnt'];
}
if($row['status'] == "X") {
$noThanks = $row['cnt'];
}
}
You have 2 sets of brackets $rs = mysql_query(($sql));
remove a set $rs = mysql_query($sql);
Add mysql_query() or die(mysql_error())
to mysql_query()
also to check for errors.
You are using a deprecated MySQL library which will be removed from future PHP releases.
Consider using mysqli
with prepared statements, or PDO with prepared statements.