Auto populated dropdown lists

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
robertws1300
Forum Newbie
Posts: 1
Joined: Tue Jul 08, 2008 1:00 pm

Auto populated dropdown lists

Post by robertws1300 »

First allow me to sheepishly admit that my only php knowledge comes from observing dreamweaver write for me.

I wish to create a series of dropdown lists, where the entries in each list are shaded initially and become populated with data (from a mysql db) that is dependent upon the previous drop-down list selection (aside from the first 'tyear' selection, of course).

I am trying to build a site for a tireshop which would output a tire size, depending on the year, make, model, submodel of the customers car.

I am even unsure of the best format of such a database.

Thanks for any insight given!
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Re: Auto populated dropdown lists

Post by Rovas »

You need to make a database which contains the tables for :1) categories of tires; 2) the tire models; 3) the manufacturer of the tires, etc. After you manually add the data into the tables then make php scripts that selects the data needed by the user.
I tried doing this once using only PHP a select box that on select would sent the selected value to the server which will build a second select containing the values for the selected category. But it was an inconvenience for the user to many callbacks to the server.
Try using AJAX and PHP: first make a PHP script that queries the database, very simple to make an example already given in thePHP manual. But instead of displayind the result in a div, you put the html tags for the select box. Second test it if it works, protect it from sql injection by using:mysql_escape_string
Third make\ copy an [http://w3schools.com/ajax/ajax_server.asp]simple AJAX script[/url] that writes into a html page the results. Link the to the PHP script and then you have your script.
If didn' t understand any of the previous copy scripts and modify for your use
Post Reply