The following code returns the value twice, once encoded in JSON :
<?php
$req = $bdd->prepare('SELECT Date, Open, Close FROM quotes WHERE Symbol = ? AND Date > ? AND Date < ?');
$req->execute(array($_GET['id'], $_GET['datemin'], $_GET['datemax']));
$test=array();
while ($donnees = $req->fetch())
{
$test[] = $donnees;
}
echo json_encode($test);
?>
[{"Date":"2012-02-29","0":"2012-02-29","Open":"88.14","1":"88.14","Close":"87.60","2":"87.60"},{"Date":"2012-02-28","0":"2012-02-28","Open":"87.83","1":"87.83","Close":"87.77","2":"87.77"},{"Date":"2012-02-27","0":"2012-02-27","Open":"87.41","1":"87.41","Close":"88.07","2":"88.07"}]
I read on some post I have to use fetch_assoc()
instead of fetch_array()
.
But the following code returns nothing : while ($donnees = $req->fetch_assoc())
. Nor does this one : while ($donnees = $req->fetch_array())
.
I don't get what's wrong.