hi i’m doing a project in php, i have 2 drop down list boxes and a radio button group, 1 drop down will pull out name of hotels, when a user picks a name from the 1st drop down and pick the area with the radio button and it must populate the 2nd drop down list box with with a list of hotels in the area. eg if i pick Hilton hotel in the 1st box and the area with radio in must give me a list of all the hilton hotels in the chosen are… i have created a table with hotel ID, ID format: hotel name/area/number, eg HHDbn001, HHDbn002 etc. i was thinking by sending the IDs in to an array, and using string manipulation if i pick hilton htell and durban it must find all the IDs that have HHDbn in it. would this be possible? and how can i code it?
This is not string manipulation. You can put them into an array in PHP but that will do nothing for you as that’s handled server-side and you want to manipulate it on the front-end. If you want to pull all of the information from your database that is relative to this then you should look into JSON (JavaScript Object Notation) and using PHP’s json_encode() ( http://php.net/manual/en/function.json-encode.php ) to populate the object. Once that is done then you can use JavaScript functions and event listeners to manipulate the text that is populated in your HTML.
Another option is to grab only the list of hotels from your database and then use AJAX to show the relevant information after a selection has been made.
Also I believe your database design is not done very well.
It seems to me that you should break the information up into at least three tables.
I have a tutorial on the functionality of the dropdowns like you want but it doesn’t take in to consideration of a radio button. This should get you started, and if nothing else you can edit your database to list the location next to the hotel in the dropdown which would eliminate the radio thing altogether.
http://amecms.com/article/Building-Chained-Select-Boxes-with-Jquery-and-PHP