Есть демка http://demos.99points.info/ajax_dropdown/ Исходник http://efimov.ws/assets/files/develop/2011/02/nlevel_ajax_d ... points.rar MYSQL таблица Код (Text): 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`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=43 ; -- -- Dumping data for table `ajax_categories` -- INSERT INTO `ajax_categories` (`id`, `category`, `pid`) VALUES (1, 'Tutorials', 0), (2, 'Demos', 0), (3, 'Entertainment', 0), (4, 'Real Estate', 0), (5, 'Web Development', 0), (6, 'Browsers', 0), (7, 'Laptop', 0), (8, 'PHP', 1), (9, 'jQuery', 1), (10, 'AJAX', 1), (11, 'CodeIgniter', 1), (12, 'PHP demos', 2), (13, 'jQuery demos', 2), (14, 'Film', 3), (15, 'Music', 3), (16, 'Commercial', 4), (17, 'Home', 4), (18, 'CSS', 5), (19, 'PHP', 5), (20, 'FireFox', 6), (21, 'Internet Explorer', 6), (22, 'Safari', 6), (23, 'Opera', 6), (24, 'IBM', 7), (25, 'Sony', 7), (26, 'Dell', 7), (27, 'HP ', 7), (28, 'Version 4', 8), (29, 'Version 5', 8), (30, 'jQuery Tutorials', 9), (31, 'jQuery Demos', 9), (32, 'Codeigniter 1.7', 11), (33, 'Codeigniter 2.0', 11), (34, 'Good Demos', 12), (35, 'Average Demos', 12), (36, 'Good Demos', 13), (37, 'Old', 28), (38, 'New', 29), (39, 'Good', 30), (40, 'Bad', 31), (41, 'Old', 32), (42, 'New', 33); Скрипт Код (Text): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Ajax Tutorial: Dynamic Loading of ComboBox using jQuery and Ajax in PHP</title> <script type="text/javascript" src="jquery-1.3.2.js"></script> <script type="text/javascript" src="jquery.livequery.js"></script> <script type="text/javascript"> $(document).ready(function() { //$('#loader').hide(); $('.parent').livequery('change', function() { $(this).nextAll('.parent').remove(); $(this).nextAll('label').remove(); $('#show_sub_categories').append('<img src="loader.gif" style="float:left; margin-top:7px;" id="loader" alt="" />'); $.post("get_chid_categories.php", { parent_id: $(this).val(), }, function(response){ setTimeout("finishAjax('show_sub_categories', '"+escape(response)+"')", 400); }); return false; }); }); function finishAjax(id, response){ $('#loader').remove(); $('#'+id).append(unescape(response)); } </script> <style> .both h4{ font-family:Arial, Helvetica, sans-serif; margin:0px; font-size:14px;} #search_category_id{ padding:3px; width:200px;} .parent{ padding:3px; width:150px; float:left; margin-right:12px;} .both{ float:left; margin:0 0px 0 0; padding:0px;} </style> </head> <?php include('dbcon.php');?> <body> <div id="show_sub_categories"> <select name="search_category" class="parent"> <option value="" selected="selected">-- Categories --</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> <br clear="all" /><br clear="all" /> </body> </html> Общий принцип строиться на выборке из базы по pid, там три колонки – id, category, pid Все категории и подкатегории находятся в одной колонке, хочется сделать выборку с привязкой к значению в колонке и формировать их во втором выпадающем списке а не генерировать его.
Код (Text): $query = "select * from ajax_categories where pid = 0"; во втором выпадающем списке нужно подставить значение выбранное в перовом вместо pid = 0 например Код (Text): $query = "select * from ajax_categories where "list 1 selected"";