is_numeric($id)); $selectedIdsList = implode(',', array_map('intval', $selectedIds)); if (empty($selectedIdsList)) { die('Invalid selection.'); } // Fetch only selected records $query = "SELECT * FROM `road_challans` WHERE id IN ($selectedIdsList) ORDER BY `id` DESC"; $result = $conn->query($query); // Set headers for Excel file download header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=transit_loss_" . date("Ymd_His") . ".xls"); header("Pragma: no-cache"); header("Expires: 0"); // Begin table output echo ""; echo ""; if ($result && $result->num_rows > 0) { $index = 1; while ($row = $result->fetch_assoc()) { $qty = is_numeric($row['quantity']) ? (float)$row['quantity'] : 0; $qty_billed = is_numeric($row['quantity_billed']) ? (float)$row['quantity_billed'] : 0; $difference = $qty - $qty_billed; echo ""; $index++; } } else { echo ""; } echo "
Sl No. Seller Company Purchaser Company Challan No. Challan Date Quantity Dispatch Quantity Unloaded Difference (Kgs)
{$index} " . htmlspecialchars($row['consignorName'] ?? '') . " " . htmlspecialchars($row['name'] ?? '') . " " . htmlspecialchars($row['challan_no'] ?? '') . " " . htmlspecialchars($row['date'] ?? '') . " " . htmlspecialchars($row['quantity'] ?? '') . " " . htmlspecialchars($row['quantity_billed'] ?? '') . " " . htmlspecialchars((string)$difference) . "
No matching data found.
";