douju6542 2015-09-02 14:51
浏览 50

Group_concat或PDO :: FETCH_ASSOC

Basically I am trying to achieve the same as stated on the link below db field(GROUP_CONCAT) as array

The reason why I am writing regarding similar question is because all the answers related to I can find related to group_concat that applies to my case are from 2011, 2012. So I am not sure if that is the best solution now days.

I have created so far this

        $sql->select( array('a.id', 'a.user_id', 'a.title', 'a.created', 'a.published', 'b.title AS obtitle', 'b.items_id'))
        ->from($this->db->quoteName('table1', 'a'))
        ->join('LEFT', $this->db->quoteName('table2', 'b'). '
        ON (' .$this->db->quoteName('a.id').'='.$this->db->quoteName('b.items_id').')')
        ->where($this->db->quoteName('a.user_id') . ' =' . $this->db->quote($userid).' AND ' .$this->db->quoteName('a.published') . ' = 1')
        ->group($this->db->quoteName('b.item_id'));

        $query = $this->db->setQuery($sql);

My question, is it still right to use group_concat? Or is it old practice (hence why I only find old answers)? would PDO::FETCH_ASSOC be more appropriate for merging the results that have a common id into an array and sub array?

  • 写回答

1条回答 默认 最新

  • dsg7513 2015-09-02 14:54
    关注

    There is nothing wrong with group_concat, yet PDO::FETCH_ASSOC offer not a slightest help in grouping anything.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大