Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3458372
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:58:29+00:00 2026-05-18T09:58:29+00:00

i have a countries, states, cities tables , and I need 3 dropdown menus

  • 0

i have a countries, states, cities tables , and I need 3 dropdown menus
wherein, if i select a country like e.g United States, the states dropdown menu will automatically show only the states that are under United States, and next, if I select a State like e.g California, the Cities drop down menu will only show off the Cities under California

am currently having problem implementing this in yii. I have this _form file
where these 3 dropdown should be included. I have a partial code, but I can’t figure out how to make this work out

this is from the Controller

public function actionDynamicstates()
{
  $sql = "SELECT StateName FROM gg_t_worldareasstates ".
         "WHERE CountryID = :countryid";
  $command = Yii::app()->createCommand($sql);
  $command->bindValue(':countryid', $_POST['CountryID'], PDO::PARAM_INT);
  $data = $command->execute();

  $data = CHtml::listData($data,'StateID','StateName');
  foreach($data as $value=>$name)
  {
    echo CHtml::tag('option',
    array('value'=>$value),CHtml::encode($name),true);
  }
}

this is from the _form view file

<div class="row">
<?php 
$country = new CDbCriteria; 
$country->order = 'CountryName ASC';
echo $form->dropDownList($model, 'CountryID', 
  CHtml::listData
  (
    Worldareascountries::model()->findAll($country),
    'CountryID',
    array
    (
      'ajax' => array
      (
        'type' => 'POST',
        'url' => CController::createUrl('wsmembersdetails/dynamicstates'),
        'update' => '#StateID',
      )
    )
  )
);
echo $form->dropDownList('StateID','', array());
?>
</div>

I changed that those codes above into this one

    <div class="row">
    <?php echo $form->labelEx($model,'Country'); ?>
    <?php 
          $country = new CDbCriteria; 
          $country->order = 'CountryName ASC';
    ?>
    <?php 
          echo $form->dropDownList($model,'CountryID',CHtml::listData(Worldareascountries::model()->findAll($country),'CountryID','CountryName'),
                    array(
                        'ajax' => array(
                        'type' => 'POST',
                        'url' => CController::createUrl('wsmembersdetails/dynamicstates'),
                        'update' => "#StateID"
                    )       
              )
          );
    ?>
    <?php echo $form->error($model,'CountryID'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'State'); ?>
    <?php 
          $state = new CDbCriteria;
          $state->order = 'StateName ASC';
    ?>
    <?php 
          echo $form->dropDownList($model,'StateID',CHtml::listData(Worldareasstates::model()->findAll($state),'StateID','StateName'),
                    array(
                        'ajax' => array(
                        'type' => 'POST',
                        'url' => CController::createUrl('wsmembersdetails/dynamiccities'),
                        'update' => '#CityID'
                    )   
                )
          );
    ?>
    <?php echo $form->error($model,'StateID'); ?>
</div>


<div class="row">

    <?php echo $form->labelEx($model,'CityID'); ?>
     <?php echo $form->dropDownList($model,'CityID','',array());?>
    <?php echo $form->error($model,'CityID'); ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:58:30+00:00Added an answer on May 18, 2026 at 9:58 am

    this problem was solved, it’s on the yii wiki docs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four tables, namely countries,states,cities,areas which will be the best feasible solution for
I have a list of cities, states/provinces, and countries and I need to find
Let's say I have an object graph of Countries / States / Cities, like
I have 4 tables namely, countries, states, cities, areas, apart from countries table the
Well here's my problem I have three tables; regions, countries, states. Countries can be
how do i organize country data (countries, states and cities etc) in mysql? cause
I have a 3 dropdowns: countries, states, and cities. States and cities are dependent
I need a list of countries, states & cities based on a collection of
So I have a MySQL database with cities/counties within the United States with longitude
anyone know of a solution? i have found online a select menu for countries,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.