• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
two drop down list from database

#1
[eluser]Unknown[/eluser]
I have two drop down list. The second drop down list will depend on the selected value in the first drop down box.

in normal PHP the code for your view will just be:

$cntry = "Select name from country;";
$sql = mysql_query($cntry);


$country = $_POST['country'];
$query = "SELECT * FROM cities where country = '$country'";


<select name="country">
while($row = mysql_fetch_array($sql))
{ <option>&lt;?=$row['countryname']?&gt;</option> }
</select>


<select name="city">
while($result = mysql_fetch_array($query))
{ <option>&lt;?=$result['countryname']?&gt;</option> }
</select>


which means you can post the value you selected in the same page and use it to query.

but in codeigniter, you cannot do that. you cannot post data unless you pass it to a model or controller. The requirement of my site is after you select in the country, it will auto populate the second drop down list without going to other pages or clicking on any button.

any help will be appreciated.

#2
[eluser]SitesByJoe[/eluser]
To change anything on your screen without changes pages will require javascript.

You would need to make a javascript function that fires anytime the 1st select menu gets changed.

This function would need to send the current select menu value to your php script which would send back the information which you would use to update your 2nd select menu.

#3
[eluser]manilodisan[/eluser]
You can have an array in javascript and use chain selects (google that) or you can use ajax to post and inject the response into your 2nd select.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.