I need to replace returned query from MySQL, if it is empty, with zero, but I can't figure out how.
For example I have table named values. There is device id and some period with values.
id_device | 2015-05-01 | 2015-05-02 | 2015-05-03 | 2015-05-04 | 2015-05-05
---------------------------------------------------------------------------
1 | 1000 | 990 | 980 | 970 | 960 |
2 | 1150 | 1140 | 1130 | 1120 | 1100 |
3 | 1050 | 1040 | 1030 | 1020 | 1010 |
4 | | | | | |
5 | 1250 | 1240 | 1230 | 1220 | 1210 |
When I use
$sql = mysql_query("SELECT * FROM values");
while ($row = mysql_fetch_array($sql)) {
if (mysql_num_rows($row) == 0) {
$row[1] = 0; $row[2] = 0; $row[3] = 0; $row[4] = 0; $row[5] = 0;
}
echo "<td>$row[1] $row[2] $row[3] $row[4] $row[5]</td>";
}
The 4th row is still empty instead of being replaced by zeros. Why? And how can I replace the empty fields with zeros?