Whatever I do, I cannot get this code to echo $done.
Here is an excerpt from my code that I just cannot get to work for the life of me. I have tried it five different ways, but nothing is working. My only conclusion is that it doesn’t work because of UNION.
Is there a way around this? Or is this even the problem?
$query01 = "SELECT COUNT(DISTINCT report) AS ip
FROM reports
WHERE country = '".$country."'
AND YEAR(date) = '2011'
AND MONTH(date) = '".$i."' AND
status ='IP'
UNION
SELECT COUNT(DISTINCT report) AS done
FROM reports
WHERE country = '".$country."'
AND YEAR(date) = '2011'
AND MONTH(date) = '".$i."'
AND status ='DONE'";
$result01 = mysql_query($query01);
while ($row01 = mysql_fetch_array($result01)) {
$ip = $row01['ip'];
$done = $row01['done'];
$all = $ip + $done;
if($all>0){
echo "<td>".$ip.":".$done."</td>";
}
else{
echo "<td>-</td>";
}
}
I guess you are trying to get the
ipanddoneas two columns of each row in which case UNION is not the right choice for the query you have.Try this: