Reputation: 3463
I have the following query in PHP:
$stmt = $conn->prepare('SELECT
date,
avg(sells) as sells
FROM `table` WHERE product_id = :id group by date having count(id) > 1');
$stmt->execute(array('id' => $product));
$res = $stmt->fetchAll(PDO::FETCH_ASSOC);
As expected this returns me:
array(2) {
[0]=> array(2) {
["date"]=> "2013-1-11" ["sells"]=> "73.5000"
}
[1]=> array(2) {
["date"]=> "2013-1-11" ["sells"]=> "77.0000"
}
}
Anyway I can get the following output without looping with php?
array(2) {
[0]=> array(2) {
"2013-1-11",
"73.5000"
}
[1]=> array(2) {
"2013-1-11",
"77.0000"
}
}
Upvotes: 3
Views: 3094
Reputation: 8767
Since you stated that you are wanting to use JSON, try something along the following:
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($result);
This will give you a valid JSON structure based off of the data returned.
Upvotes: 1