sbmoba
(Bhu2y Silent)
1
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
jowen
(Ljowen985)
2
Hi rangga,
you can try
$sql = 'SELECT substr(name,5) as number from mytable';
$result = Yii::app()->db->createCommand($sql)->queryAll();
sbmoba
(Bhu2y Silent)
3
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
jowen
(Ljowen985)
4
$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.