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 ?
Use this method to get records from the table having socials_user column value equal to 1.
You are using a Model from YII. Models always represent one Object in YII. That's why it looks like that there is a
LIMIT 1
as you described it.You need to query the database instead to return a set of rows. Here is some YII database access example code to give a picture how that works (from here):
I do not know if you already have a database connection set up, but I assume so as you're already using a database. So this is what you need to access the DB Command object then to actually call
query()
(from here):Hopefully this information if of use to you.
better yet, use findAllByAttributes.
your code should be:
Doc : http://www.yiiframework.com/doc/api/1.1/CActiveRecord#findAllByAttributes-detail