Question

I am having a problem with a city dropdown menu. the situation is like this, I have 3 tables. namely countries, states, cities, I was able to generate a dropdown menu for Countries, States.. I was able to generate a dropdown menu for Cities also but, the problem is, when I pushed the code to production server, the page turned white due to too much memory consumption, here's my code

//model
    public function fetchCityName()
    {
        $connection = Yii::app()->db->createCommand("SELECT CityName from gg_t_worldareascities ORDER BY CityName ASC")->queryColumn();
        return $connection;

    }

//view
        <?php 
            $this->widget('CAutoComplete', array(
                'model' => $model,
                'attribute' => 'cityID',
                'data' => $model->fetchCityName(),
                'multiple' => false,
                'htmlOptions' => array('size' => 25),
            ));
        ?>
Was it helpful?

Solution

See this wiki on creating dependent dropdowns in Yii:

http://www.yiiframework.com/wiki/24/creating-a-dependent-dropdown/

I think you'd be better going with an autocomplete though - the docs are here:

http://www.yiiframework.com/doc/api/1.1/CJuiAutoComplete

It is the jQuery UI Autocomplete which is widely used.

OTHER TIPS

If you have 216,912 option elements, it should ring an alarm bell that there is a better way :)

May I suggest

  • Autocomplete that queries your server with AJAX.
  • Pick postcode first, then show matching suburbs.

I don't do Yii, but there should be some kind of relationships between countries, states, cities right? No one would select city of Taipei then choose CA, U.S.A. as the country and state.

For the States and Cities, I would suggest fetch the acceptable choices via Javascript/AJAX only after the user have selected the Country/State.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top