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.

Read Also:  Move Background Image on Mouseover Using jQuery

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

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.

Read Also:  Convert Array to XML and XML to Array using PHP

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Smooth Scroll to ID using jQuery
  2. Read Also:  jquery reload page Automatically Example
  3. Read Also:  Vue js Multi level sidebar Dropdown menu
  4. Read Also:  Show country state city dropdown select box using javascript
  5. Read Also:  jQuery AJAX laravel 6 Delete Data from database
  6. Read Also:  PHP Dynamically Add Remove Images Upload using Ajax
  7. Read Also:  Laravel Calculate Age from Date of Birth in MySQL
  8. Read Also:  javascript dynamic drop down list country state city
  9. Read Also:  How to check array is empty or not in php?
  10. Read Also:  country state city drop down list using JavaScript