I want to display all data in tables according to date. I store data from database in array to be displayed. But I got error warning:undefined array key. Below is my code to store data in array.
include("db.php");
if(isset($_GET['from_date']) && isset($_GET['to_date'])){
global $conn;
$from_date = $_GET['from_date'];
$to_date = $_GET['to_date'];
$stmt = $connection->prepare("
SELECT
date(datetime_entry_queue) AS Date,
duration_wait
FROM call_entry
WHERE status='abandonada'
AND date(datetime_entry_queue) BETWEEN '$from_date' AND '$to_date'
");
$stmt->execute();
$result = $stmt->get_result();
$Data = null;
while($row = $result->fetch_assoc()) {
if($row['duration_wait'] >= 0 AND ($row['duration_wait'] <= 30))
{
$Data[$row['Date']]['0-30'] += 1;
}
else if($row['duration_wait'] >= 31 AND ($row['duration_wait'] <= 60))
{
$Data[$row['Date']]['31-60'] += 1;
}
else if($row['duration_wait'] >= 61 AND ($row['duration_wait'] <= 120))
{
$Data[$row['Date']]['61-120'] += 1;
}
else
{
$Data[$row['Date']]['>120'] += 1;
}
}
echo "<pre>";
print_r($Data);
echo "</pre>";
$stmt->close();
}
This how I return the data in the table on my page:
<?php
foreach($Data AS $Date => $Total)
{
?>
<tr>
<td><?php echo $Date;?></td>
<td><?php echo $Total["0-30"];?></td>
<td><?php echo $Total['31-60'];?></td>
<td><?php echo $Total['61-120'];?></td>
<td><?php echo $Total['>120'];?></td>
</tr>
<?php
}
?>
I already run my query and it shows all the data I needed.