我认为数据库操作在指南中没有得到很好的解释.我无法理解.因为这个我有一个问题.我问Yii论坛,但没有任何答案.这是我的社交表格.
+------------+---------------------------+--------------+--------------+---------------+
| 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 |
+------------+---------------------------+--------------+--------------+---------------+
Run Code Online (Sandbox Code Playgroud)
我想从这个表中获取socials_user collumn等于1的所有数据.可以有几行(在这个例子中有3行).
我应该用什么方法?我正在尝试这个:
$allSocial = '';
$socials=Socials::model()->findByAttributes(array('socials_user'=>1));
foreach ($socials as $social)
{
$type = $social["socials_type"];
$allSocial .= $type . ",";
}
return $allSocial;
Run Code Online (Sandbox Code Playgroud)
但这会返回4,l,8,1,4.(第一行的每个第一个字母/数字)
我怎么用呢?findByAttributes AR是否正在添加LIMIT 1;
到SQL?
使用此方法从socials_user列值等于1的表中获取记录.
$socials=Socials::model()->findAll('socials_user=:socials_user', array(':socials_user'=>1));
Run Code Online (Sandbox Code Playgroud)