dplece1882 2014-12-23 22:23
浏览 108

带有mysql的PHP Dropdownlist表单

Hey, i am about to make a form which should contain 4 dropdownlists... And by dropdownlists i mean selects in html/php - the "preview" of what i am thinking about, there's a link in the bottom, so you can get a better understanding of what i am talking about.

I've been searching for some, and i found this code in a tutorial, it is working and all this, but i would like to have 4 dropdownlists instead of only 2. I have seen some without querystring, but this code is with querystring, and i'm not quite the best at php, but i understand a lot, thats not a problem, but problem is, that i would like to get rid of querystring and get 2 more dropdownlist, but i don't know the way to do it.

it's not a problem to get 2 more dropdownlist, but to get 2 more dropdownlist working like the link in the bottom.

I want it to work so i have to choose the first dropdownlist and rest are disabled or just empty, and when i choose in the first dropdownlist the second dropdownlist will be enabled or filled with data which is connected with the first like, a car and in the next BMW etc. should show up, and then when you have choosed in the second dropdownlist, the third dropdownlist will be enabled or filled with data just like the second one, but now if you choose BMW you should pick a model like M5 or M3 etc. and when you have done that, you will be able to pick the engine of the M5 or M3 or whatever you are choosing.

///////// Getting the data from Mysql table for first list box//////////
$quer2="SELECT DISTINCT category,cat_id FROM category order by category"; 
///////////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory///// 
if(isset($cat) and strlen($cat) > 0){
$quer="SELECT DISTINCT subcategory FROM subcategory where cat_id=$cat order by subcategory"; 
}else{$quer="SELECT DISTINCT subcategory FROM subcategory order by subcategory"; } 
////////// end of query for second subcategory drop down list box ///////////////////////////

echo "<form method=post name=f1 action='dd-check.php'>";
/// Add your form processing page address to action in above line. Example  action=dd-check.php////
//////////        Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
foreach ($dbo->query($quer2) as $noticia2) {
if($noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";}
else{echo  "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";}
}
echo "</select>";
//////////////////  This will end the first drop down list ///////////

//////////        Starting of second drop downlist /////////
echo "<select name='subcat'><option value=''>Select one</option>";
foreach ($dbo->query($quer) as $noticia) {
echo  "<option value='$noticia[subcategory]'>$noticia[subcategory]</option>";
}
echo "</select>";
//////////////////  This will end the second drop down list ///////////
//// Add your other form fields as needed here/////
echo "<input type=submit value=Submit>";
echo "</form>";
?>

Like i mentioned earlier, i have been searching for some results, and then i also found this. This is what i am talking about, this is without querystring, and is doing exactly what i would like to. I have tried looking into the code (F12) but can't find some php or javascript or jquery.

http://www.sedox-performance.com/tfconfigurator/dealers?lang=en&color=blue&bg=white&txt=black&title=blue

  • 写回答

1条回答 默认 最新

  • dszpyf4859 2014-12-23 22:48
    关注

    Quite a few methods available. You want a dropdown's options to be filtered based on the previous dropdown selection, right? If lists are not too long then build and send them down with the page-load, then filter child options on parent's select event. Else if the lists are very long then use AJAX to pull child lists on parent's select event. Use JSON to transport and / or manage the lists and JQuery (or straight JavaScript) to dynamically populate and repopulate the lists.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程