I'm looking to build a mysql php drop down... I have seen things like ajax and what not.. but I'm not sure what the best way to go about this is. Pretty much I have Make > Models for cars, like ebay or auto trader Make Models Make will match up with with whats in the model table make is listed in the same row as the model... So when you select ford Ford : f150 - will show ford : mustang will show etc...
Store the Make and Models in separate tables(in db). A demo schema would look like: tblMake -------- id make_name tblModel -------- id model_name make_id (primary key of tblMake) Code (markup): In this way, the db would be in normalized form. Now for populating the "Make" combobox, just query the tblMake for all records. Then echo it enclosing the <option> tag inside a <select>, which will create the comboboxes. And then, using javascript, add a listener for the change event of the combobox(Make's). So that, whenever user changes the selection, it should do an ajax query to a php file with that particular make_id and this php script would return all the models that matches this make_id, from db. So, make use of this resulting list to dynamically populate the Model's combobox(using javascript). I hope you got the idea.
I don't think you understood my question. I'm looking for the format of the Tables and Columns so I can give you an answer to your question. Without knowing what your database structure is, we would have to make a hundred and one assumptions.
I have the idea.. its more along the idea of getting the drop downs to work correctly... make> then Model >
That's still not clear. But let's see... Most Make/Model databases have a single Table holding all the relative info (Id, Make, Model, Trim, ..., etc). I'm going to assume your database has separate tables holding the data for Models and Makes with using the "id" as the key between the two. *IF* my assumption is correct you would run 2 queries. Query 1: SELECT id FROM Makes WHERE make = "Ford"; Query 2: SELECT model FROM Models WHERE id = "The_Id_You_Just_Fetched_Here"; -OR you can wrap it up with a single query using a JOIN... In this case there really isn't much of a performance difference. Edit: Just re-read your original post and saw you were asking how to load the data in to the dropdowns. You probably already have the SQL code so just ignore my above post.
netstar what is not clear? ---------------------------- I can get both to load right now.. but all the chevy models show up under the ford models... I just got to the point now where I think im going to need some type of javascript, or ajax.. and now thats the part i am stuck on.
nope no more ideas... I have done it before.. but I just have been so rusty... The Java or ajax part is what I am having a problem with i think... I mean its the only way to make something like that work correct?
something like this - http://www.usedcars.com/ where the one section is blurred out untill you select the make. but with just make model.
I think, ajax would be the easy way. If you could use jQuery(which is a pretty easy JavaScript), there is get(), post(), ajax() methods. You could use one of them. Another way would be to store all makes and models in JavaScript arrays(just echo it in PHP) and make use of the data from these to dynamically populate them at client side. The advantage is, this doesn't need the server's help to get the list of models specific to each make. Because we are not contacting the server and making it execute a query to fetch all models of a particular make and using it(via ajax). But I think, if you have a large of data in your db tables, then this might not be a good approach.
I will have to brush up on the java and ajax i guess.. the model table has to pull from the database no matter what.. they want they want to add models without doing any code editing.. thank you though
Just use an event handler, that will be triggered when the "make" select changes it's value. The event handler should then pull of the corresponding models from the server with a simple GET ajax request and place those values in the "model" select. That's it.