Usman Iqbal
Usman Iqbal

Reputation: 2429

How to write this query in yii and print it without using foreach loop?

I have written this query in sql and it is working fine, I am getting the exact result which I wanted, but when I write this query in Yii, and if I do not use foreach loop I get this error array to string conversion. Query in sql

SELECT description FROM `comment_business` where review_business_id=72;

Query in Yii

 $results=Yii::app()->db->CreateCommand()  
                                ->select('description')
                                ->from('comment_business b')
                               ->where('b.review_business_id='.$ba->id)
                                ->queryRow();
     echo $results;

I know in sql, I get the description, but here, how can I achieve my results, without using foreach loop ?

I have

Upvotes: 2

Views: 223

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133380

if you get an only row try

echo $result['description'];

if you get more than a row you need index

 echo $result[0]['description'];

Upvotes: 1

Related Questions