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 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统