I have a method below, that selects some comments. I'm having issues getting the data, not because the query doesn't work but the while loop doesn't fetch the data if I don't use an array, here is my code
public function selectAllComment($idarticle) { $db = $this->getBdd();
$sql = $db->query('SELECT c.comment, c.date_comment
FROM comments as c
INNER JOIN joint_a_comments on joint_a_comments.id_comment = c.id
INNER JOIN articles a ON joint_a_comments.id_article = a.id
WHERE a.id ="'.$idarticle.'"
ORDER BY c.date_comment DESC
LIMIT 0,10');
while($result[] = $sql->fetch(PDO::FETCH_ASSOC))
{
$rescomment[] = new Comments($result);
}
return $rescomment;
With this above, I can see that the data are fetched using var_dump on $result. However, first problem is: 1- if I do the same with the object i.e. $rescomment (I instantiate a class to hydrate the data and I use them in a view...). 2- If I remove the brackets [] from $result, I get "boolean false"....any idea guys?