SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Populating A Drop Down Menu with Selection of a Previous Drop Down Menu

    Hello,

    I am attempting to populate an HTML drop down menu based on the selection from a previous drop down menu and access to MySQL Database fields. I would like to populate three drop downs in total based on the data contained in the MySQL database. I already have built and have access to my database.

    Year
    Make
    Model

    I would use javascript, but the make and model fields in the database are populated with several thousand entries. Is there a more effective/efficient way to populate these fields? If so, I would be very much open to recommendations or HTML/PHP scripting examples.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Welcome to the SP forums.
    You might want to take a look at AJAX. Do a google search for 'AJAX drop down' or something like that and you should fine loads of tutorials and examples.

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,136
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Peakbagger View Post
    Hello,

    I am attempting to populate an HTML drop down menu based on the selection from a previous drop down menu and access to MySQL Database fields. I would like to populate three drop downs in total based on the data contained in the MySQL database. I already have built and have access to my database.

    Year
    Make
    Model

    I would use javascript, but the make and model fields in the database are populated with several thousand entries. Is there a more effective/efficient way to populate these fields? If so, I would be very much open to recommendations or HTML/PHP scripting examples.
    How often does this data change? Usually for data that isn't mission critical, I use a scheduled task or a cronjob to write out the information to a flat file that I can just use a <?php include('path to file'); ?> on so the HTML is already built and can be easily included into your document. Then I schedule the task or cronjob to run nightly, weekly, whatever makes sense.

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    Is it that time of year again? You might want to look at what last year's students did when they asked us to do their homework for them too. Search the forum a bit.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the recommendation and welcoming--most of what I've found already is AJAX oriented--I'll give that a shot. The Make, Model and Year values update per annum, but I do have other variables that will update as quickly as every five minutes. Sorry, StarLion, but I wish I was still in school. I'm a few years beyond that now and am just getting into server-side scripting.

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If you are going to attempt a server-side only solution, you probably only need 2 webpages.

    1 Pick year and make. ("2000" and "Ford")

    2 Show models (available matching models)

    .... then possibly link on to another page showing just that model?

    I think we'd need to know what fields you have in each table, I'm especially interested to hear what you have in your "year" table ...

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,169
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Hi Peakbagger, welcome to the forums,

    In school or out, we could all stand to learn a few things

    If I understand you correctly, you have an initial form containing "common to all" selects, that when once chosen will lead to specific "not common to all" choices.

    You are correct in wanting to get this to work server-side, javascript and AJAX can embellish the user's experience, but you want things to work for everyone, including those without javascript.

    So maybe something like this:

    Initial page populates the select with the "common" values taken from the database.
    Form sends input values to server.
    Server finds applicable "specific" values and sends back a second form using those values.
    Form sends those input values to the server.
    Server sends back the final page.

    You may be interested in using the QuickForm2 package as it would save you from a lot of work.
    This package provides methods to create, validate and render HTML forms.

    Features:
    * Supports all form elements defined by HTML standard, provides several
    custom elements
    * Server-side and client-side validation, several common rules provided
    * Multipage forms (tabbed forms and wizards)
    * Pluggable elements, rules, renderers and renderer plugins

    Major advantages over PHP4 version:
    * Most of the package's functionality is covered by unit tests
    * DOM-like API for building the form structure, new streamlined API for
    elements' values handling
    * Default rendering without tables (inspired by
    HTML_QuickForm_Renderer_Tableless)
    * Renderer plugins for elements with complex rendering needs
    * Ability to chain validation rules with 'and' and 'or'
    * Client-side validation can run "live" on changing the form fields,
    validation errors are displayed near the fields instead of in alert()


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •