开发者

how can i make a dynamic drop down box in php?

开发者 https://www.devze.com 2023-01-01 06:22 出处:网络
i need in an php file three drop down boxes or multiple select boxes. the entries from these boxes are in a mysql database.

i need in an php file three drop down boxes or multiple select boxes.

the entries from these boxes are in a mysql database.

the single problem is that the entries in the thrid box depend on the second, and the entries in the second depend on the first.

can someone help? know any example开发者_开发百科s?


There are basically 3 ways to achieve this:

  1. Use JavaScript to submit() the form to the server side during onchange of the dropdown and let PHP load the options and render the child dropdown accordingly based on the selected dropdown value. Technically the simplest way, but also the least user friendly way. You probably also want to revive all other input values of the form.

  2. Let PHP populate all possible child dropdown values in a JavaScript array and use a JavaScript function to fill and display the child dropdown. A little bit trickier, certainly if you don't know JavaScript yet, but this is more user friendly. Only caveat is that this is bandwidth and memory inefficient when you have relatively a lot of dropdown items. Imagine three dropdowns which can each hold 100 items, that would mean a JS array of 100 * 100 * 100 = 1 million items. The page might then grow over 1MB in size.

  3. Let JavaScript fire an asynchronous (ajaxical) HTTP request to the server side and fill and display the child dropdown accordingly. Combines the best of options 1 and 2. Efficient and user friendly. jQuery is extremely helpful in this since it removes the concerns about crossbrowser compatibility with regard to firing ajaxical requests and traversing the HTML DOM tree. You would otherwise end up with double, triple or even much more of code needed to achieve this.


If you let know in a comment or an update of your question which way you would prefer and where exactly you're stucking while implementing the solution, then I'll maybe update the answer to include a basic kickoff example.


I'm from Portugal, so, what we do it's based on Portuguese language, never the less, we've made many working websites and platform's with what you want, please check this link...

if this is what you want, I can send you the code:

http://www.medipedia.pt/home/home.php?module=farmacia

0

精彩评论

暂无评论...
验证码 换一张
取 消