country state city drop down list in php mysql

Today, We want to share with you country state city drop down list in php mysql.In this post we will show you Responsive country,state,city dropdown values from the database without refresh page using Ajax and PHP, hear for 3 drop down of country,state,city, drop downs without refreshing the page. we will give you demo and example for implement.In this post, we will learn about Country State City Dynamic Dependent Dropdown Using Jquery In Codeigniter with an example.

Here, i will learn you how to populate country state city in dropdown list in php mysql using jquery ajax.

Read Also:  javascript dynamic drop down list country state city

country state city drop down list in php

All the country, state, city data and their licensing is 100% free to use so you can use this all the data for any commercial as well as non commercial web or mobile applications.

country state city Dynamic dependent dropdown using jquery in codeigniter
country state city Dynamic dependent dropdown using jquery in PHP

Include JS files

<script src="https://www.pakainfo.com/js/jquery.min.js"></script>
<script src="https://www.pakainfo.com/js/custom.js"></script>   

config_database.php Page

<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'Paka888***@#$');
define('DB_DATABASE', 'area_master');
$connection = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE) or die(mysqli_error());
?>

SearchRegion.php Page

<?php
/** Search city based on country
* @author : Rakesh Dave <www.pakainfo.com>
*/
 
#include database configuration file
require_once('config_database.php');
$country_id = $_GET['country_id'];
$districts_data=mysqli_query($connection,"SELECT * FROM district where country_id = $country_id ORDER BY district");
$districts = array();
while($district = mysqli_fetch_assoc($districts_data)){
 array_push($districts, $district);
}
print_r(json_encode($districts));
 
?>

SearchCity.php Page

<?php
/** Search city based on states
* @author : Rakesh Dave <www.pakainfo.com>
*/
 
#here simple include mysql database configuration file
require_once('config_database.php');
$district_id = $_GET['district_id'];
$districts_data=mysqli_query($connection,"SELECT * FROM city where district_id = $district_id ORDER BY city");
$districts = array();
while($district = mysqli_fetch_assoc($districts_data)){
 array_push($districts, $district);
}
print_r(json_encode($districts));
 
?>

I hope you get an idea about country state city database in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.