ohctech_p8/medicine_details_chart.php

44 lines
1.0 KiB
PHP
Raw Normal View History

2024-10-16 19:18:52 +05:30
<?php
include('includes/config/config.php');
$labels = array();
$data = array();
$ohc_id = $_SESSION['current_ohcttype'];
$sql_query = "SELECT ti.item_name, COUNT(si.item_id) + COUNT(t.item_id) as count
FROM stock_issue_items si
LEFT JOIN tbl_items ti ON si.item_id = ti.item_id
LEFT JOIN treatment t ON si.item_id = t.item_id
WHERE ti.ohc_type_id = ?
GROUP BY ti.item_id
ORDER BY count DESC
LIMIT 0,10";
$stmt = mysqli_prepare($conn, $sql_query);
if (!$stmt) {
error_log("Error preparing statement: " . mysqli_error($conn));
2024-11-02 18:03:13 +05:30
die();
2024-10-16 19:18:52 +05:30
}
mysqli_stmt_bind_param($stmt, "s", $ohc_id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)) {
$name = $row['item_name'];
$count = $row['count'];
$labels[] = $name;
$data[] = $count;
}
mysqli_stmt_close($stmt);
$response = array(
'labels' => $labels,
'data' => $data
);
echo json_encode($response);