// Validate and add date filters if provided
if (!empty(start_date)) {
conditions[] = "DATE(o.created_at) >= ?";
params[]=start_date;
types .= "s";
}
if (!empty(end_date)) {
conditiparams[] = types .= "s";
}
// Append WHERE clause if there are conditions
if (count(conditions) > 0) {
sql .= " WHERE " . implode(" AND ", $conditions);
}
$sql .= " ORDER BY o.created_at DESC";
// Prepare and execute statement
stmt=conn->prepare($sql);
if (stmt) {
if (count(params) > 0) {
stmt−>bindparam(types, ...params);
}
stmt->execute();
rstmt->get_result();
code
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . date('Y-m-d', strtotime($row['created_at'])) . "</td>";
echo "<td>#{$row['order_id']}</td>";
echo "<td>" . htmlspecialchars($row['customer_name']) . "</td>";
echo "<td>{$row['item_count']}</td>";
echo "<td>₱" . number_format($row['final_total'], 2) . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='5'>No orders found for the selected date range.</td></tr>";
}
$stmt->close();
} else {
echo "Error preparing the query.";
}
?>
can you make the chart functional
Assistant
To make the chart functional in your admin dashboard, we'll use Chart.js (a lightweight, popular JavaScript charting library) to render a line chart showing sales trends over time. Here's how to implement it: