dqs86517 2017-04-08 21:11
浏览 10

使用连接表获取选择,while循环需要一个数组,否则不会获取任何内容

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?