<?php 
	include '../config.inc.php';
	
	//$sql = "SELECT * FROM tblCafea;";


	$sql = "
	SELECT c.id,
c.denumire,
c.origine,
v.IDcafea,
GROUP_CONCAT(v.Variatie),
GROUP_CONCAT(v.Pret),
c.poza
FROM `tblCafea` c
LEFT JOIN `tblVariatii` v
ON c.`id` = v.`IDCafea`
GROUP BY v.IDCafea
ORDER BY c.id
	";

	$result = mysqli_query($conn,$sql);
	
	$response = array();


$sqlVer = "SELECT * FROM tblVersionare";

$resultVer = mysqli_query($conn,$sqlVer);



while ($rowVer = mysqli_fetch_row($resultVer))
{
    $ver = $rowVer[1];
}


array_push($response,array("Version"=>$ver));

	while ($row = mysqli_fetch_array($result)) 
	{
		array_push($response, array("ID"=>$row[0],"Denumire"=>$row[1],"Origine"=>$row[2],"Variatie"=>$row[4],"Pret"=>$row[5],"Poza"=>$row[6]));
	}

/*
    echo "<pre>";
	echo json_encode(array("server_response"=>$response), JSON_PRETTY_PRINT);
    echo "</pre>";*/

echo json_encode(array("server_response"=>$response));

	//echo json_encode($response);

	
	mysqli_close($conn);

?>