Reading Multiply Rows From Database

Hello,

I think database operations isn’t explained very well, on guide . I couldn’t understand it. Because of this i have a question. 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"];

			$link = $social["socials_link"];

			$allSocial .= "<li><a href=\"". $this->make_link($type,$link) ."\" rel=\"nofollow\"><img src=\"images/social/". strtolower($this->get_socials_name($type)) .".png\" alt=\"\" > ".$this->get_socials_name($type)."</a></li>";

		}

		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 ?

In general, the find* functions return a single row. You should call the findAll* version.

Secondly, if you pass an array to a find function, you must assign keys to the value. Try removing the array and just pass condition string.

->find("socials_user=1"); ?


Socials::model()->findAll('socials_user=:id', array(':id' => 1))