Good Day. Here my question: i want to display the result if the count get from the SQL is more than 0, if the count is 0, then the result will not display. Here the current output after adding if else statement in my php :
{"result":[]}
This is the output before adding if else statement in my php:
{ "result": [
{"day":"1","count":"0"},
{"day":"2","count":"2"},
{"day":"3","count":"0"},
{"day":"4","count":"0"}....
I want the result only like tis :
{"result":[
{"day":"2","count":"2"}
]}
Here my php code:
define('HOST','xx');
define('USER','xx');
define('PASS','xx');
define('DB','x');
//$month = $_POST['month'];
//$year = $_POST['year'];
$month = 10;
$year=2016;
$con = mysqli_connect(HOST,USER,PASS,DB);
$result = array();
for ($day=1 ; $day<=31 ; $day++) {
$sql = "select count(entryID) from Entry where
EXTRACT(DAY FROM(entryTime)) = '$day' AND
EXTRACT(MONTH FROM(entryTime)) = '$month' AND
EXTRACT(YEAR FROM(entryTime))= '$year'";
$res = mysqli_query($con,$sql);
if($row[0] >0)
$day2 = (string)$day;
while($row = mysqli_fetch_array($res)) {
array_push($result,
array('day' =>$day2,
'count' => $row[0]
));
}
}
}
echo $appear . json_encode(array("result"=>$result));
mysqli_close($con);
?>
Aucun commentaire:
Enregistrer un commentaire