Jump to content

dropdown country state city using ajax


harpalsinh999

Recommended Posts

it is main file retrive here data of drop down but not retrive data ?

not display country in the select list so plaese help me

it is main.php

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head><body> <table><tr><td>Country </td><td><select name="country" id="country" onchange="getState(this.value)"><option value="-1">Select Country</option><?php$cntry = mysql_query("SELECT `Country_Id`, `name` FROM country ORDER BY `name` ASC");while($row = mysql_fetch_assoc($cntry)){echo '<option value="'.$row['Country_Id'].'">'.$row['name'].'</option>';}?></select></td></tr><tr><td>State </td><td>: <select name="state" id="state" onchange="getCity(this.value)"><option value="-1">Select State</option></select></td></tr><tr><td>City </td><td>: <select name="city" id="city" ><option value="-1">Select City</option> </select></td></tr></table></body></html>

Edited by harpalsinh999
Link to comment
Share on other sites

it is getcity.php

 

 

<?php$link = mysql_connect("localhost","root","");$dbSelected = mysql_select_db('pra_countrystate');$id="-1,";$cname="Select City,";$sid = $_GET['sid'];if($sid=="-1"){$response = $id."|".$cname;echo $response;}else{$result = mysql_query("SELECT `city_id`, `city_name` FROM `city` WHERE `state_id` = ".$sid." ORDER BY `city_name` ASC");while($row = mysql_num_rows($result)){$id .=$row['city_id'].",";$cname .=$row['city_name'].",";}$response = $id."|".$cname;echo $response;}?>

Edited by harpalsinh999
Link to comment
Share on other sites

it is getstate.php

 

<?php$link = mysql_connect("localhost","root","");$dbSelected = mysql_select_db('pra_countrystate');$id="-1,";$sname="Select State,";$cid = $_GET['cid'];if($cid=="-1"){$response = $id."|".$sname;echo $response;}else{$result = mysql_query("SELECT `state_id`, `name` FROM `state` WHERE `country_id` = ".$cid." ORDER BY `name` ASC");while($row = mysql_fetch_assoc($result)){$id .=$row['state_id'].",";$sname .=$row['name'].",";}$response = $id."|".$sname;echo $response;}?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...