country state city Dynamic dependent dropdown using jquery in codeigniter

country state city Dynamic dependent dropdown using jquery in codeigniter

In this Post We Will Explain About is With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to dependent drop down list in codeigniter Example

In this post we will show you Best way to implement Dynamic Dependent Select Box using jQuery, Ajax and PHP, hear for country state city drop down list using ajax in codeigniter with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Codeigniter – Dynamic dependent dropdown using jquery ajax Example

In this Example,First of all Add or Inluce External Libs Like as a(jQuery, css etc..), and then create a simple index.php or index.html page.After that crate a simple javascript file like as a index.js or main.js, It is also add your web-application First Header Part to some priorty set.After that Include your relavant CSS Class.

Phase 1: Download Fresh Codeigniter 3

In First step or init step we will simple step by step download fresh version of PHP based Like as a Codeigniter 3, so if We haven’t download yet simple here then download from here latest version free download: Download Codeigniter 3

Phase 2: Create Database and Configuration

CREATE TABLE `state_rec` (
  `id` int(11) NOT NULL,
  `name` varchar(155) NOT NULL,
  `cr_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `up_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

live_cities table:

CREATE TABLE `live_cities` (
  `id` int(11) NOT NULL,
  `cur_stid` int(12) NOT NULL,
  `name` varchar(155) NOT NULL,
  `cr_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `up_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

config using Codeigniter

application/config/database.php

 '',
	'hostname' => 'localhost',
	'username' => 'YOUR_USERNAME',
	'password' => 'YOUR_PASSWORD',
	'database' => 'DATABASE_NAME',
	'dbdriver' => 'mysqli',
	'dbprefix' => '',
	'pconnect' => FALSE,
	'db_debug' => (ENVIRONMENT !== 'production'),
	'cache_on' => FALSE,
	'cachedir' => '',
	'char_set' => 'utf8',
	'dbcollat' => 'utf8_general_ci',
	'swap_pre' => '',
	'encrypt' => FALSE,
	'compress' => FALSE,
	'stricton' => FALSE,
	'failover' => array(),
	'save_queries' => TRUE
);

Phase 3: Add Route

application/config/routes.php


Phase 4: Create Controller

application/controllers/liveController.php

load->database();
   }

   /**Devloped by Pakainfo.com free download examples
   */
   public function index() {
      $states = $this->db->get("state_rec")->result();
      $this->load->view('liveform', array('states' => $states )); 
   } 

   /**Devloped by Pakainfo.com free download examples
   */
   public function liveformAjax($id) { 
       $result = $this->db->where("cur_stid",$id)->get("live_cities")->result();
       echo json_encode($result);
   }

} 

?>

Phase 5: Create View Files

application/views/liveform.phpIn this Last step, You will create a simple on server liveform.php view after that here you will make HTML form with simple input box two dropdown like as a select box. you also bellow source code ajax code here:




    Pakainfo.com - Codeigniter Dependent Dropdown step by step Example with demo
    
    




Select simple State and get bellow Related City

cmd commands quick run

php -S localhost:8000

Codeigniter rnu in browser

http://localhost:8000/liveform

You are Most welcome in my youtube Channel Please shubscibe my channel. and give me FeedBackMore Details......
Angularjs Example

Example

I hope you have Got What is country state city drop down list using ajax in codeigniter And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.

Leave a Comment