#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    17
    Rep Power
    0

    Unhappy Populating dropdowns


    I'm trying to dynamically populate a dropdown fom a database MySQL db using Python. I am stuck. Can somebody please help on how to get started or point in right direction? Thanks in advance!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    89
    Rep Power
    13
    so what exactly don't you understand? you grab the info out of the db and write it in the HTML form.
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    As 2k said, there isn't really a lot to get stuck on here but anyway here's a little example - this doesn't use any db since i don't have any data to populate this t with.

    Code:
    #!/usr/bin/env python
    
    print 'Content-Type: text/html\n'
    
    values = ['Name1', 'Name2', 'Name3', 'Name4']
    
    print'<form name="form">'
    print'<select name="names">'
    print'<option selected>Netytan</option>'
    
    for value in values:
        print'<option>%s</option>' % value
    
    print'</select>'
    print'</form>'
    Note: 'values' can be a simple cursor or list/tuple object. needs a little reworking if you want to use dictionaries but it shows you exactly what you need.... so, a loop

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    17
    Rep Power
    0

    Talking


    Thanks netytan. I kinda figured out myself but appreciate your example!

    Originally Posted by netytan
    As 2k said, there isn't really a lot to get stuck on here but anyway here's a little example - this doesn't use any db since i don't have any data to populate this t with.

    Code:
    #!/usr/bin/env python
    
    print 'Content-Type: text/html\n'
    
    values = ['Name1', 'Name2', 'Name3', 'Name4']
    
    print'<form name="form">'
    print'<select name="names">'
    print'<option selected>Netytan</option>'
    
    for value in values:
        print'<option>%s</option>' % value
    
    print'</select>'
    print'</form>'
    Note: 'values' can be a simple cursor or list/tuple object. needs a little reworking if you want to use dictionaries but it shows you exactly what you need.... so, a loop

    Mark.

IMN logo majestic logo threadwatch logo seochat tools logo