// ========================================== // 2. MEDICATION OPTIONS AND URL FILTER // ========================================== $medications = [ "aspirin" => "Aspirin", "ibuprofen" => "Ibuprofen", "penicillin" => "Penicillin", "lipitor" => "Lipitor", "paracetamol" => "Paracetamol" ]; // Default medication $filter = "aspirin"; // Read medication from the URL if (isset($_GET["medication"])) { $requested = strtolower(trim($_GET["medication"])); // Only allow medications listed above if (array_key_exists($requested, $medications)) { $filter = $requested; } } $medicationName = $medications[$filter]; // ========================================== // 3. QUERY THE DATABASE // ========================================== $sql = " SELECT AVG(Age) AS AverageAge, MIN(Age) AS LowAge, MAX(Age) AS HighAge, COUNT(Name) AS NumberPatients FROM healthcare_dataset WHERE medication = ? "; $stmt = $mysql->prepare($sql); if (!$stmt) { error_log("SQL preparation failed: " . $mysql->error); exit("Sorry, the dashboard could not load."); } $stmt->bind_param("s", $medicationName); $stmt->execute(); $results = $stmt->get_result(); $currentrow = $results->fetch_assoc(); $patients = (int) $currentrow["NumberPatients"]; $avgage = $currentrow["AverageAge"] !== null ? round((float) $currentrow["AverageAge"], 1) : null; $lowage = $currentrow["LowAge"] !== null ? (int) $currentrow["LowAge"] : null; $highage = $currentrow["HighAge"] !== null ? (int) $currentrow["HighAge"] : null; $stmt->close(); $mysql->close(); ?> Medication Health Dashboard

Medication Health Dashboard

Patient statistics for
Warning: Undefined variable $medicationName in /home/junzhuch/public_html/acad274/health chart ai.php on line 299