T
T
The Dragger2015-05-01 13:02:47
Yii
The Dragger, 2015-05-01 13:02:47

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);
    }

Checked Sql request in basis all correctly returns.
<?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')); ?>

But in php an empty array is returned, why? and what is wrong here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
The Dragger, 2015-05-01
@IPD2

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 question

Ask a Question

731 491 924 answers to any question