I have a table which calculates the cost based on time.I need to display table based on time with 1 hour limit. If time is greater than 1 hour it should display null in the cost column.How can I do that.
dashboard.php
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db_name = "test2";
$lastId="";
$date = strtotime('now') - 3600;
print_r($date);
$week = strtotime('now') - 604800;
$month = strtotime('now') - 2592000 ;
//create connection
$con = mysqli_connect($host, $user, $pass, $db_name);
//test if connection failed
$result = mysqli_query($con,"SELECT SUM(cost) FROM track_data WHERE start_time >
DATE_SUB(NOW(), INTERVAL 1 HOUR) ");
$result1 = mysqli_query($con,"SELECT SUM(cost) FROM track_data WHERE start_time >
DATE_SUB(NOW(), INTERVAL 1 WEEK)");
$result2 = mysqli_query($con,"SELECT SUM(cost) FROM track_data WHERE start_time >
DATE_SUB(NOW(), INTERVAL 1 MONTH)");
?>
<div class="col-md-6 col-md-offset-3">
<table class="table table-hover table-striped">
<tr class="t_head">
<th> Days </th>
<th> Usage </th>
<th> Total Cost </th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
echo "<tr id='emp_salary'>";
echo "<td> Today </td>";
echo "<td>1 Hour</td>";
echo "<td>" .$row[0]. "</td>";
echo "</tr>";
}
?>
</table>
</div>
As u can see the above image the total cost column is empty. Instead of empty value I should get NUll or Zero.