javascript - Multiple dropdown elimination form using PHP and MySQL -


i having quite hard time figuring out. basically, form several dropdown menus. user select 1 or multiple items dropdowns filter out mysql data results. eliminate options user fills in form. so, example, user selects "nike" , "adidas" brands menu, other dropdown menus should updated , show list either related "nike" or "adidas". let's countries dropdown menu no longer list countries , instead show usa (nike) , germany (adidas). , on , forth other dropdown menus.. here php/html code.

<?php  // connection require_once('./db.inc.php');   $brands_list_query = "select distinct brand inventory order brand asc"; $brands_list_result = mysql_query($brands_list_query) or die('error, brands listing failed: ' . mysql_error()); $brands_list = ""; while($brands_list_row = mysql_fetch_assoc($brands_list_result)) {     $brand = $brands_list_row['brand'];     $brands_list .= "<option value=\"$brand\">$brand</option>\n"; }  $countries_list_query = "select distinct country inventory order country asc"; $countries_list_result = mysql_query($countries_list_query) or die('error, countries listing failed: ' . mysql_error()); $countries_list = ""; while($countries_list_row = mysql_fetch_assoc($countries_list_result)) {     $country = $countries_list_row['country'];     $countries_list .= "<option value=\"$country\">$country</option>\n"; }  $models_list_query = "select distinct model inventory order model asc"; $models_list_result = mysql_query($models_list_query) or die('error, models listing failed: ' . mysql_error()); $models_list = ""; while($models_list_row = mysql_fetch_assoc($models_list_result)) {     $model = $models_list_row['model'];     $models_list .= "<option value=\"$model\">$model</option>\n"; }  $shapes_list_query = "select distinct shape inventory order shape asc"; $shapes_list_result = mysql_query($shapes_list_query) or die('error, shapes listing failed: ' . mysql_error()); $shapes_list = ""; while($shapes_list_row = mysql_fetch_assoc($shapes_list_result)) {     $shape = $shapes_list_row['shape'];     $shapes_list .= "<option value=\"$shape\">$shape</option>\n"; }  // close connection mysql_close();  ?> <!doctype html> <html> <head> <link rel="stylesheet" href="select2/select2.css">   <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> <script src="select2/select2.js"></script>  <style type="text/css"> .select_width {     width: 180px; } </style>  <script>   $(function(){ // turn element select2 select style $('#select1').select2(); $('#select2').select2(); $('#select3').select2(); $('#select4').select2();   }); </script> </head> <body> <form target="browser" method="get" action="browser.php">  brands:<br /> <select name="brands[]" id="select1" class="select_width" multiple="multiple"> <?php echo $brands_list; ?> </select>  </br >  countries:<br /> <select name="countries[]" id="select2" class="select_width" multiple="multiple"> <?php echo $countries_list; ?> </select>  </br >  models:<br /> <select name="models[]" id="select3" class="select_width" multiple="multiple"> <?php echo $models_list; ?> </select>  </br >  shapes:<br /> <select name="shapes[]" id="select4" class="select_width" multiple="multiple"> <?php echo $shapes_list; ?> </select>  <input type="submit" name="submit" value="update" /> <input type="reset" value="reset">  </form>  </body> </html> 

mysql table

create table `inventory` (   `brand` varchar(15) collate utf8_unicode_ci not null,   `country` varchar(15) collate utf8_unicode_ci not null,   `model` varchar(25) collate utf8_unicode_ci not null,   `reference` varchar(15) collate utf8_unicode_ci not null,   `shape` varchar(25) collate utf8_unicode_ci not null,   `details` varchar(200) collate utf8_unicode_ci not null ) 

how may go on this? jquery needed update lists user updates form? or there way? thank in advance!

add onclick or onchange event on each of selection boxes call js function build url iframe on page.

since have multiple selections, have pass array; "inventorysearch.php?brand=adidas,nike&country=us,uk&andsoon".

the php page builds query select inventory table based on selection criteria passed in query string, in "where brand in('adidas', 'nike')..." , fetches database , displays in table.

the tricky parts in assembling querystring (catering select boxes have no selections), , likewise clause of sql.

is enough go on?


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -