duanhe1976 2011-06-19 17:51
浏览 25
已采纳

在Yii框架中从数据库中读取多行

I think database operations isn't explained very well, on guide . I couldn't understand it. Because of this i have a question. I asked it Yii Forums but there isn't any answer. This is my socials table for example.

+------------+---------------------------+--------------+--------------+---------------+
| socials_ID | socials_link              | socials_type | socials_user | socials_order |
+------------+---------------------------+--------------+--------------+---------------+
|         48 | link                      |            8 |            1 |             4 |
|         47 | blablabla                 |           11 |            1 |             3 |
|        301 | userlinkuse               |            9 |            1 |             6 |
+------------+---------------------------+--------------+--------------+---------------+

I want to get all datas from this table which socials_user collumn equals to 1 . There can be a few rows (in this example there are 3 rows) .

What method should i use ? I'm trying this :

                $allSocial = '';
                $socials=Socials::model()->findByAttributes(array('socials_user'=>1));
                foreach ($socials as $social)
                {
                        $type = $social["socials_type"];
                        $allSocial .= $type . ",";
                }
                return $allSocial;

but this is returning 4 , l , 8 ,1 , 4 . (First letter / number of every collumn on first row)

How can i use it ? findByAttributes AR is adding LIMIT 1; to SQL ?

  • 写回答

3条回答 默认 最新

  • duandian8110 2011-06-19 18:43
    关注

    Use this method to get records from the table having socials_user column value equal to 1.

    $socials=Socials::model()->findAll('socials_user=:socials_user', array(':socials_user'=>1));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

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