In a php file (ajax_chart.php) I have this
$search=$_POST['present'];
if(!empty($search)){
include '../main_includes/connect_db.php';
$present_day = date("d");
$present_month = date("m");
$present_year = date("y");
for ($i=0;$i<=23;$i++){
$total_visitors_present=[];
$query="SELECT * FROM visitors WHERE visitor_day=$present_day AND visitor_hour=$i AND visitor_minute<=59 ";
$select_query= mysqli_query($connect, $query);
$num_visitors[$i]= intval(mysqli_num_rows($select_query));
array_push($total_visitors_present, $num_visitors);
}
echo json_encode($total_visitors_present[0]);
}
and in another php file (charts.php) in script tag I have the following Ajax code
$.ajax({
url: 'includes/ajax_chart.php',
data:{present:'present'},
type: 'POST',
success: function (data) {
if(!data.error){
console.log(data);
}
}
});
The console output is weird.
while that i expected to output is the following array
[0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
What am I doing wrong?
How i retrieve the array with ajax?