Jump to content
Sign in to follow this  
harpalsinh999

dropdown country state city using ajax

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

Share this post


Link to post
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

Share this post


Link to post
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;}?>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...