<?php require_once("../../db.php"); ?>
<?php try {
	
		$core = Core::getInstance();
		$stmt = $core->dbh->prepare("SELECT count(*) as sum FROM (SELECT count(*) FROM messages LEFT JOIN myclients on mess_client_id = client_id WHERE ag = :ag group by mess_client_id) as subquery");
		$stmt -> bindParam("ag", $_GET["ag"], PDO::PARAM_INT);
		
		
		$stmt -> execute();
		$results = $stmt -> fetchAll(PDO::FETCH_ASSOC);
		
		echo $results[0]["sum"];
		
	
		//echo $results["sum"];
		
	} catch(PDOException $pe) {
		
		trigger_error('Could not connect to MySQL database. ' . $pe->getMessage() , E_USER_ERROR);
		
	}
?>