Ajax Tutorial: Dynamic Loading of ComboBox using jQuery and Ajax in PHP

Here is a script for beginners to create a dynamic loading of dropdown. Simple solution which is created by jQuery.
Table Structure
CREATE TABLE IF NOT EXISTS `ajax_categories` ( `id` int(11) NOT NULL AUTO_INCREMENT, `category` varchar(50) NOT NULL, `pid` int(11) NOT NULL, PRIMARY KEY (`id`) )
get_child_categoires.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?php if($_REQUEST) { $id = $_REQUEST['parent_id']; $query = "select * from ajax_categories where pid = ".$id; $results = mysql_query( $query);?> <select name="sub_category" id="sub_category_id"> <option value="" selected="selected"></option> <?php while ($rows = mysql_fetch_assoc(@$results)) {?> <option value="<?php echo $rows['category'];?> ID=<?php echo $rows['id'];?>"><?php echo $rows['category'];?></option> <?php }?> </select> <?php }?> |
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <div class="both"> <h4>Select Category</h4> <select name="search_category" id="search_category_id"> <option value="" selected="selected"></option> <?php $query = "select * from ajax_categories where pid = 0"; $results = mysql_query($query); while ($rows = mysql_fetch_assoc(@$results)) {?> <option value="<?php echo $rows['id'];?>"><?php echo $rows['category'];?></option> <?php }?> </select> </div> <div class="both"> <h4 id="show_heading">Select Sub Category</h4> <div id="show_sub_categories" align="center"> <img src="loader.gif" style="margin-top:8px; float:left" id="loader" alt="" /> </div> </div> |
Who I Am

Zeeshan Rasool
Software Engineer - PHP
Lahore - Pakistan
zeeshan(@)99points.info
Skype: zeeshan-rasool
gTalk: zishan.rasool85
Categories
- AJAX (37)
- Codeigniter (16)
- CSS (16)
- Facebook (12)
- Joomla (1)
- JQuery (54)
- Miscellaneous (4)
- Mootools (1)
- MySQL (6)
- PHP (60)
- SEO (2)
- Technology (6)
- Tutorials (17)
- Twitter (2)
- Web Design (24)
- Web Development (59)
- WordPress (2)
Tags
99points
adobe
AJAX
ajax pagination
ajax rating
ajax tutorial
ajax voting system
captcha
Codeigniter
codeigniter 2.0
codeigniter recaptcha
CSS
css tutorials
dreamweaver cs5
Facebook
facebox
farmville
ffmpeg
flv
google api
hacking
Joomla
JQuery
JQuery Gallery
JQuery menus
jquery plugins
Jquery tutorial
mafia war
Mootools
MySQL
pagination
PHP
php curl
recaptcha
RSS Feed
SEO
simplepie
socail networking
ssl
Tutorials
Twitter
wall script
Web
XSS
youtube
Comments
- ZeeShaN on Ajax Shopping Cart: Create a Stylish Shopping Cart Using JQuery and PHP
- Blogzpoint on Super Ajax Polling/Voting System using JQuery, Ajax, PHP and MySQL
- Blogzpoint on Super Ajax Polling/Voting System using JQuery, Ajax, PHP and MySQL
- Nick on Ajax Shopping Cart: Create a Stylish Shopping Cart Using JQuery and PHP
- Nick on Ajax Shopping Cart: Create a Stylish Shopping Cart Using JQuery and PHP
ZeeShaN







thanks a lot.
How can i get sub categories of child?
ex: after select main cat , next combobox show me children’s of it.and how can i show children’s of selected child in combobox?
please help me.thanks
hi ,thanks, i need to do styles for this select box, it possible?? any tutorial for tht??
love it
Hi,
Thank you so much, but I have to ask;
If I use 2 tables in one SQL database, how can we coding?..
For example;
First combo will use table1 data (id1, categori1, pid1)
Second combo will use table2 data (id2, categori2, pid2)
How can we connect these two tables?
Thank you so much.
great.. i found what i want.
thanks alot
Thanks Brother
Thanks mark
Very nicely written..
Thank you so much for Sharing!
Very Cool Article! I need to know how can increase sub selections? like Category -> Brand -> Prod -> Color like
thank you very much. I a new deverlop web.
knowledge is very litle. I need you help!
hay contac to my mail please!