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 (11)
- Joomla (1)
- JQuery (53)
- Miscellaneous (4)
- Mootools (1)
- MySQL (6)
- PHP (60)
- SEO (2)
- Technology (6)
- Tutorials (15)
- Twitter (2)
- Web Design (23)
- Web Development (57)
- 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 tutorial
mafia war
Mootools
MySQL
pagination
Payment
PHP
php curl
recaptcha
RSS Feed
SEO
simplepie
socail networking
ssl
Tutorials
Twitter
wall script
Web
XSS
youtube
Comments
- ZeeShaN on Facebook Wall Script Clone with JQuery and PHP: Personal Project BETA Version 2.0
- 20 + Fresh jQuery Image Gallery/Slider Plugins and Tutorials Worth a Look | free on JQuery Based Flipped Image Gallery with Bounce Effects
- 20 + Fresh jQuery Image Gallery/Slider Plugins and Tutorials Worth a Look | free on Fresh JQuery Image Gallery with Captions and Auto Play/Pause Rotation
- 25 Cool and Helpful jQuery Plugins/Tutorials For Your Next Project | free on jQuery Tutorial: Create jQuery and CSS based Awesome navigation.
- 25 Cool and Helpful jQuery Plugins/Tutorials For Your Next Project | free on Ajax Tutorial: How to Create Ajax Search Using PHP jQuery and MYSQL
ZeeShaN






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!
A very helpful code.
One question, and maybe the same with the others, is it possible to join tables or use multiple table? I am trying but not displaying any result. Please help..
ex.
id tableCountry
id tableCity parentID
id tableState parentID
Thank you so much.
Is this applicable with multiple table? please help. I have my separate my subcategory table with id and parent id.