<?php
$conn = new PDO("mysql:host=localhost;dbname=bishopk3_qb","bishopk3_root1","pass2023.bk");

if(isset($_POST["action"]))
{

	if($_POST["action"] == 'fetch')
	{
	  
      $query="SELECT pupils.Claz as claz, COUNT(pupils.count) AS Total  FROM pupils where pupils.Status='Active' GROUP BY claz";  
	  $result = $conn->query($query);
	  $data = array();

		foreach($result as $row)
		{
			$data[] = array(
				'claz'		=>	$row["claz"],
				'total'			=>	$row["Total"],
				'color'			=>	'#' . rand(100000, 999999) . ''
			);
		}

		echo json_encode($data);
	}
}
?>