I'm trying to retrieve values from a database and encode them as JSON for another script to grab. I'm doing this like this:
for($i=0; $i<7; $i++)
{
$nextDay = $i+1;
$startDateTime = date("Y-m-d H:i:s", strtotime("-$i days"));
$endDateTime = date("Y-m-d H:i:s", strtotime("-$nextDay days"));
$query = "select count(*) as cnt from app_instances where (time between '$endDateTime' and '$startDateTime') and (app_id = '$appId') group by title";
$result = $database->prepare($query);
$result->execute();
$row = $result->fetch();
$count = (int)$row['cnt'];
if($count==null){
$count = 0;
}
$thisVal = array();
$thisVal[]= $count;
array_push($dataArray,$thisVal);
}
$thisContent = json_encode($dataArray);
This gives the result:
[[30],[152],[45],[34],[56],[67],[56]]
But what I really need is something like:
[[1, 30], [2, 152], [3, 45], [4, 34], [5, 56], [6,67], [7, 56]]
But if I try to add the key to the array manually, it returns as objects.
Can anyone help?