开发者

Easiest way to create drop down with database generated options

I'm trying to build a multi-level "game". A randomly generated option (Option1) will trigger other options in a drop down (Option2)...the options in the new drop down wi开发者_开发问答ll be directly related the to Option1. Option2 will then trigger another drop down with info directly related to Option2 and so forth until reaching OptionEnd...any suggestions, preferably SQL and PHP.

Thanks...yeah, I'm a n00b.


Table: option
id int
parent_id int
option_name varchar

When an option is selected $id = that option's id. Then:

SELECT * FROM option WHERE parent_id = $id;

And use those results to populate the new drop down.


You'll also probably want to use AJAX to dynamically populate the further options once each one is selected - otherwise you'll need a page refresh every time.


the easiest way is probably to use a library or plugin. check out this jQuery dependent select plugin; it looks pretty solid: http://plugins.jquery.com/project/DependentSelect

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜