Answer the question
In order to leave comments, you need to log in
Why does an SQL query return an empty array?
Hello!!
working on yii1
public static function regionsByMahala (){
$sql = "SELECT rrr.id, rrr.name_ru, rrr.name_uz, rrr.name_en
FROM `ref_mahala` rm
LEFT JOIN ref_region rr ON rm.district_id = rr.id
LEFT JOIN ref_region rrr ON rr.parent_id = rrr.id
GROUP BY rrr.id";
return $db = RefMahala::model()->findBySql($sql);
}
<?print_r(CHtml::listData(RefRegion::regionsByMahala(), 'id', 'name_ru'))?>
<?php echo $form->dropDownList($model,'parent_id', CHtml::listData(RefRegion::regionsByMahala(), 'id', 'name_ru'), array('empty'=>Yii::t("region", 'Выберите регион'), 'class'=>'span3')); ?>
Answer the question
In order to leave comments, you need to log in
Damn already found the answer, you just had to google in English
public static function regionsByMahala (){
$sql = "SELECT rrr.id, rrr.name_ru, rrr.name_uz, rrr.name_en
FROM `ref_mahala` rm
LEFT JOIN ref_region rr ON rm.district_id = rr.id
LEFT JOIN ref_region rrr ON rr.parent_id = rrr.id
GROUP BY rrr.id";
$connection=Yii::app()->db;
$db = $connection-> createCommand($sql);
$row = $db->queryAll();
// $db = RefMahala::model()->findBySql($sql);
return $row;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question