tags:

views:

60

answers:

3

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 will 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.

A: 
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.

Syntax Error
While Nicholai's link was informative...I also need something else a bit more simpler.Yours might present that.Like I said, I'm a newbie and if you explain what the lines accomplish that makes it easy. I have a project I need help with.List 1 will create List 2 List 1 will be from a single database tableList 2 will be from a single database table that has references to List 1's tableAfter List 2's option is selected, another "List 1" will be created from references in the sql database.I.E.Artist AlbumArtist(featured on albmum above) Albumand so on
All can be accomplished with 1 table and you can have an infinite number of lists. Example everything from list 1 will have the parent id 0. So SELECT * WHERE parent_id=0 and you have list 1. Now let's say you select The item on list 1 that has the id of 4... You would SELECT * WHERE parent_id=4, and now you have list 2. You can keep doing this forever with just 1 table.
Syntax Error
A: 

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.

Gary
A: 

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

Nicholai