E
E
Evgeny-app2014-10-01 08:12:39
Yii
Evgeny-app, 2014-10-01 08:12:39

How to display the number of (for example) vacancies next to the name of the city?

How to make such a thing: there is a list of cities and next to it you need to display the number of vacancies in this city
. For example: Moscow 34 (vacancies), St. Petersburg 23 (vacancies), etc. I wrote a sql query that displays the number of vacancies in the database by city id, but I don’t know how to describe it in yii
Request:

SELECT cityId, COUNT(*) FROM mnk_vacancy GROUP BY city_id

And here is a function that displays a list of cities
public function getCityList()
    {
        $cityList = $this->findAll(array('order' => 'name'));
        $cityArray = CHtml::listData($cityList, 'id', 'name');
        return $cityArray;
    }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2014-10-01
@Evgeny-app

$connection=Yii::app()->db; 
command=$connection->createCommand($sql);
$rowCount=$command->execute(); // execute the non-query SQL
$dataReader=$command->query(); // execute a query SQL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question