<?php


header('Access-Control-Allow-Origin: *');


header('Content-Type: application/json');





$conn = new mysqli("agrituademo.mysql.db","agrituademo","Karim1993","agrituademo");





// Perform query


mysqli_set_charset($conn,"utf8mb4");


	


$sql = "SELECT * FROM `agritun_recolte` where `id_parcel`=".$_GET['id_parcel'];





$result = $conn->query($sql);





if ($result->num_rows > 0) {





  while($row = $result->fetch_assoc()) {	





$total += $row['nbr_pieds']; 


$cout += $row['cout']; 





	if ($row['q_unite']=="كغ"){


		$hay_kg += $row['hay']; 


		$nchira_kg += $row['nchira']; 


	}


	if ($row['q_unite']=="شكارة"){


		$hay_chkara += $row['hay']; 


		$nchira_chkara += $row['nchira']; 


	}








  }


if ($hay_kg > 0){


	$hay .= $hay_kg." <i style=' color: grey;font-size: 14px; '> كغ </i> ";


}


if ($hay_chkara > 0){


	if ($hay_kg > 0){


		$hay .= "  <i style=' color: grey;font-size: 14px; '> و </i>  ";


	}


	$hay .= $hay_chkara." <i style=' color: grey;font-size: 14px; '> شكارة </i> ";


}





if ($nchira_kg > 0){


	$nchira .= $nchira_kg." <i style=' color: grey;font-size: 14px; '> كغ </i> ";


}


if ($hay_chkara > 0){


	if ($nchira_kg > 0){


		$nchira .= "  <i style=' color: grey;font-size: 14px; '> و </i>  ";


	}


	$nchira .= $nchira_chkara." <i style=' color: grey;font-size: 14px; '> شكارة </i> ";


}


}








$conn -> close();








echo '{"total":"'.$total.'","hay":"'.$hay.'","nchira":"'.$nchira.'","cout":"'.$cout.'"}';





?>