SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2011
    0 Post(s)
    0 Thread(s)

    Pulling <option> values from mySQL database.

    OK, I have been searching, reading tutorials, and learning for 3 days now... I have found examples of code that do things kinda similar to what I want to do, but nothing that shows me exactly what I'm missing. It seems to me that what I'm trying to do is not rocket science, and should be as simple as placing some variables in the <option> lines, but I guess I'm so much of a noob that I just can't see it.

    Please help if you can, or tell me to get lost if its not worth it.

    I have drop down select boxes that looks like the example below.


    <select style="width: 630px" name="Partopt" size="1">
    <option value="10.00">select part one</option>
    <option Selected value="15.00">select part two</option>
    <option value="20.00">select part three</option>
    <option value="25.00">select part four</option>


    I would like to control the information in the Option tags with a mySQL database. So, I created a database table that looks like this...


    DB Name = Partopts

    partID | Price | Desc
    part01 | 10.00 | select part one
    part02 | 15.00 | select part two
    part03 | 20.00 | select part three
    part04 | 25.00 | select part four


    So, what is happening on my web page is I'm using drop down boxes like above with multiple parts in multiple places on multiple pages. When it comes time to update my prices and descriptions, it becomes a serious undertaking that is long, tedious, and hard to do without messing something up. So, I though it would be nice to keep all of my information in one database so that I only have to update it once. (instead of multiple places)

    Is there an easy way that a noob like me can fill in the option boxes with proper Price and Desc from the mySQL table that I created? Then with variables in the Option boxes, all I have to do is edit the info in the database.
    Any help would be greatly appreciated.

    Thank You in advance!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Toronto, Canada
    63 Post(s)
    3 Thread(s)
    what you're asking for is certainly easy to do

    however, it isn't really a mysql question

    if you could mention which application language you're planning to use (php?) we can have the thread moved to that forum | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict bimalpoudel's Avatar
    Join Date
    Feb 2009
    Kathmandu, Nepal
    0 Post(s)
    0 Thread(s)
    Definitely, you should put all your information in the database first.
    Then, while you need to draw the options/dropdown, make a small php script.
    It should query on your database for 2 columns; some ID probably like partID here.
    And, readable text, like a combination of price and description.
    Loop through the results and make your <option value="...">...</option> within the <select> tags.
    Thats all.

    Once you change your database information, it immediately comes into your web pages.
    And as many data you have in your database, the corresponding <options> are created.
    Look at the basic example here.
    Bimal Poudel @ Sanjaal Framework over Smarty Template Engine

    Hire for coding support - PHP/MySQL


Posting Permissions

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