Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-04-2004, 05:21 AM
WebProWorld New Member
 

Join Date: Apr 2004
Posts: 2
johnwrightson RepRank 0
Default PHP/MySQL - Populating the Select option of an HTML Form

Hi

I am new to PHP, but have programmed in Powerbuilder for many years.

My problem is that I wish to provide a search/update facility to my Genealogy website and cannot seem to provide the user with a list of towns stored in a MySQL table, via a drop down list box (i.e., the Select option of HTML forms).

I have tried using the SQL SELECT and populating the HTML SELECT option of the HTML Form, but cannot. Is this possible? If not is there a different method.

regards John
Reply With Quote
  #2 (permalink)  
Old 04-04-2004, 09:49 AM
sijpie's Avatar
WebProWorld Pro
 

Join Date: Sep 2003
Location: Scotland
Posts: 108
sijpie RepRank 0
Default

I'm not a php programmer, but I achieve exactly what you require in ASP, and it should be pretty easy to transpose the code to PHP.

Code:
    sql = "SELECT ModelName FROM [PDA_Data]ORDER BY ModelName"
    rsPDA.Source =  sql
	rsPDA.open()
    If rsPDA.eof Then
        rsPDA.AddNew
    End If

	do while not rsPDA.eof
	        strMdlOptions = strMdlOptions & "<option>"
		strMdlOptions = strMdlOptions & rsPDA("ModelName")
		strMdlOptions = strMdlOptions & "</option>" & vbNewLine
		rsPDA.MoveNext
	loop
The strMdlOptions should now consist of each of the models surrounded by option tags.
This can then be used in your form:
Code:
<SELECT NAME="Model">
<% = strMdlOptions %>
</SELECT>
(here the <%= strMdlOptions%> inserts the strMdlOptions, use the php equivalent)

That should work a dream.
__________________
Jaap

PalmVenue
Broekhuizen Paintings
MacSijp

You've done it all
You've broken every code (Steve Harley)
Reply With Quote
  #3 (permalink)  
Old 04-04-2004, 03:11 PM
WebProWorld New Member
 

Join Date: Apr 2004
Posts: 2
johnwrightson RepRank 0
Default Thanks Jaap

Hi Jaap

You were right it did work a dream. I had previously tried the ideas but because I was new to php with no support I kept going round in circles.

I notice you are in Scotland, so am I (nr Kilmarnock) small world eh!

regards John
Reply With Quote
  #4 (permalink)  
Old 04-05-2004, 02:27 AM
sijpie's Avatar
WebProWorld Pro
 

Join Date: Sep 2003
Location: Scotland
Posts: 108
sijpie RepRank 0
Default

Yeah, Scotland is where all the good guys live... ;)

Glad it works
__________________
Jaap

PalmVenue
Broekhuizen Paintings
MacSijp

You've done it all
You've broken every code (Steve Harley)
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0