在 Yii 框架上从数据库中读取多行 [英] Reading Multiply Rows From Database On Yii Framework

查看:47
本文介绍了在 Yii 框架上从数据库中读取多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为指南中没有很好地解释数据库操作.我无法理解.因此,我有一个问题.我问它 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 |
+------------+---------------------------+--------------+--------------+---------------+

我想从这个表中获取 socials_user 列等于 1 的所有数据.可以有几行(在本例中为 3 行).

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;

但这是返回 4 , l , 8 ,1 , 4 .(第一行每列的第一个字母/数字)

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

我该如何使用它?findByAttributes AR 正在将 LIMIT 1; 添加到 SQL 中?

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

推荐答案

使用此方法从表中获取 socials_user 列值为 1 的记录.

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));

这篇关于在 Yii 框架上从数据库中读取多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆