469,898 Members | 1,581 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Auto populate fields from sql database.

I need some help or tips on the following.

I have a .sql database file with the folowing structure:

Expand|Select|Wrap|Line Numbers
  3.   `id` int(10) default NULL,
  4.   `Make` text,
  5.   `Model` text,
  6.   `Year_` text,
  7.   `Car_Fuel` text,
And here is a sample of the data inserted in to this database:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO `car` (`id`, `Make`, `Model`, `Year_`, `Car_Fuel`) VALUES
  2. (1, 'Toyota', '4Runner SR5 4x4', '2004', 'Gasoline'),
  3. (2, 'Ford', 'Fiesta 1.4', '2003', 'Diesel'),
  4. (3, 'Seat', '4Runner SR5 4x4', '2004', 'Diesel'),
  5. (4, 'Volkswagen 2.0', 'Golf', '2008', 'Gasoline'),
  6. (5, 'Nissan', '300z', '2004', 'Petrol'),
  7. (6, 'Ford', 'Fiesta 1.8', '2005', 'Gasoline'),
  8. (7, 'Porsche', '356 America', '1952', 'Diesel'),
  9. (8, 'Lancia', 'Hit', '1988', 'Gasoline'),
And so on... up to 42000 different cars

How would I get around to make auto populating dropdown boxes selecting data from the database in the following order:

First dropdown: Make
Second auto populate: Car_Fuel
Third: Year
And then only show the Models acording to the above.

Thanks beforehand for any help or tips at all, I have done other scripts but on this one I dont know where to start.
Oct 4 '09 #1
4 4534
3,406 Expert 2GB
Unfortunately classic ASP doesn't do this for you automatically. First you will need to connect to the db, then pull the data you are interested in in a recordset (similar to a DataTable in .NET). Do you need help with this part?

After you have that done, you just need to loop through the db as you fill in the <select> drop down options. This is fairly easy, so don't worry about it until you have the first part done.

The tricky part is how do you get the second drop down box to respond to the selections you make in the first drop down (so if you select "Ford" make sure only Ford models are available in the next drop down). For this ASP is not sufficient, you will need to branch out to Javascript or Ajax. Anyway, let me know when you have the first part done, and I'll try to give you a hand on the next step.

Oct 5 '09 #2
You see I have fair knowledge of php but lacking knowledge of AJAX, I'm willing to pay for this script if someone is interested in making it.

keep in mind it should only show the years a make of cars has and further on only the fuel types for make and year, so finally you only get the models of cars according to [Make] --- populate ---->[Year] --- populate ----> [Fuel] --- populate ----> [Models] the reason is to eliminate misspellings by the user and then when the listing is submitted other data comes up according to the model selected (As could be number of doors, fuell milage and so on...)

The Sample sql I have provided is only for referance, it has many more colums in the table car: (`id`, `Make`, `Model`, `Year_`, `Car_Fuel`, 'another', 'another'...)

But I only want the Auto populating drop downs at this moment.
Oct 5 '09 #3
3,406 Expert 2GB
Well, I've seen a couple ways to do it before Ajax got big. A lot of sites used to submit the form after the first selection is made, then the page is reloaded with everything in place, the second select ready. I've also seen it done with a whole bunch of selects in hidden divs, then the correct div made visible when on e selection is made. If both of those sound awkward, then you see the reason why Ajax is used. I can help with either of those other options, but if you want an ajax solution (or if you want to contact an Ajax expert) post in the javascript/ajax forum.

Oct 5 '09 #4
564 Expert 512MB
Hello olidenia,

I am not interested in making money from helping you out. But, if you want to donate funds to BYTES then I am sure the owners of the site would appreciate it very much.

What I am interested in is providing solutions to people that need help. Do you what a example solution in Classic ASP? I know Jhardman is willing to help out too..

Oct 9 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by David Shorthouse | last post: by
5 posts views Thread by Geoff Portbury | last post: by
1 post views Thread by Jim | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.