I'm using SELECT
to collect multiple rows from my database.
Using the query format below I have the expected result.
while ($this->result = $this->pQuery->fetch(PDO::FETCH_ASSOC)) {
$this->json[] = $this->result;
}
result:
[
{
"evaluate_rq_id" : "10",
"evaluate_rq_user_id" :"5",
"evaluate_rq_client" : "[email protected]",
"evaluate_rq_comment" : "Por favor, nos avalie.",
"evaluate_rq_date" : "2014-12-27 22:21:23"
},
{
"evaluate_rq_id" : "11",
"evaluate_rq_user_id" : "5",
"evaluate_rq_client" : "[email protected]",
"evaluate_rq_comment" : "Por favor, nos avalie.",
"evaluate_rq_date" : "2014-12-27 22:23:33"
},
{
"evaluate_rq_id" : "12",
"evaluate_rq_user_id" : "5",
"evaluate_rq_client" :"[email protected]",
"evaluate_rq_comment" : "Por favor, nos avalie.",
"evaluate_rq_date" : "2014-12-28 10:45:05"
}
]
Using this format I have only 1 return line.
while($this->result = $this->pQuery->fetchAll(PDO::FETCH_ASSOC)) {
foreach($this->result as $row) {
$this->json['evaluate_rq_id'] = $row['evaluate_rq_id'];
$this->json['evaluate_rq_user_id'] = $row['evaluate_rq_user_id'];
$this->json['evaluate_rq_client'] = $row['evaluate_rq_client'];
$this->json['evaluate_rq_comment'] = $row['evaluate_rq_comment'];
$this->json['evaluate_rq_date'] = $row['evaluate_rq_date'];
}
}
result:
{
"evaluate_rq_id": "12",
"evaluate_rq_user_id": "5",
"evaluate_rq_client": "[email protected]",
"evaluate_rq_comment": "Por favor, nos avalie.",
"evaluate_rq_date": "2014-12-28 10:45:05"
}
My idea of using the second format is to set the date field to the d-m-Y
format before generating the result in JSON
format, as below:
$this->json['evaluate_rq_date'] = date("d-m-Y", strtotime($row['evaluate_rq_date']));
Any idea how to generate multiple lines using the second format?