query problems

hello…im just started using yii for 2 weeks…i have difficulty for translating mysql query to yii query.

this is my query : ‘select substr(id,7) as number from mytable’

what is the yii query for this mysql query? and how can i read the array resulted from that query?

thanks in advance to whoever reply my question

Hi rangga,

you can try


        $sql = 'SELECT substr(name,5) as number from mytable';


        $result = Yii::app()->db->createCommand($sql)->queryAll();

thanks for your response…

I already try that…but what I dont understant is how to read it…from your explanation, it should be :

foreach($result as $id){

echo $id[‘number’];

}

but it won’t work


        $sql = 'SELECT substr(name,5) as number from mytable';


        $result = Yii::app()->db->createCommand($sql)->queryAll();

above code will result an array. You need


 print_r ($result) 

to show the result. Try and see.

thanks jowen its solved