Reply
Populating drop down menu with MySQL
Old 06-27-2008, 11:50 AM Populating drop down menu with MySQL
drew22299's Avatar
Skilled Talker

Posts: 89
Location: Wiltshire, UK
Hi,

Can someone help me modify this code?

I am using the following code to populate a drop down menu with mysql output to allow the user to select a name in a form.

PHP Code:
// SQL QUERY
 
while($queryIds->fetchInto($queryId))
        {
            
$id=$queryId["personId"];
            
$forename=$queryId["first_name"]." ".$queryId['surname'];
            
$options.="<OPTION VALUE=\"$id\">".$forename."</OPTION>";
        } 
// Ene of while
 
echo "
        <SELECT NAME='person'>
        <OPTION VALUE=.$id.>Person "
.$options."
        </SELECT>"

How can I make the names in the drop down menu have a field name / value that can be used when the form is submitted?

For example, with a drop down menu that doesn't have mysql each option has a value which can then be used. In the drop down menu I'm using it displays names of people and I want the value of the option for each person to be the personId stored in the database for that person.

Any suggestions?
__________________
www.hotlista.co.uk

Last edited by drew22299 : 06-27-2008 at 11:54 AM.
drew22299 is offline
Reply With Quote
View Public Profile Visit drew22299's homepage!
 
When You Register, These Ads Go Away!
Old 06-27-2008, 03:26 PM Re: Populating drop down menu with MySQL
rogem002's Avatar
Webmaster Talker

Posts: 607
Name: Mike
Location: United Kingdom
Shouldn't it look more like:

PHP Code:
// SQL QUERY
 
while($queryIds->fetchInto($queryId))
        {
            
$id=$queryId["personId"];
            
$forename=$queryId["first_name"]." ".$queryId['surname'];
            
$options.="<OPTION VALUE=\"$id\">".$forename."</OPTION>";
        } 
// Ene of while
 
echo "<SELECT NAME='person'>".$options."</SELECT>"
__________________
Website Services
PHP Code:
if(Added_Talkupation($post) == TRUE){iHug($you);} 

Last edited by rogem002 : 06-27-2008 at 03:30 PM.
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 06-28-2008, 12:10 AM Re: Populating drop down menu with MySQL
Skilled Talker

Posts: 61
Either:

PHP Code:
// SQL QUERY

echo '<select name="person">';
 
while(
$queryIds->fetchInto($queryId))
        {
            
$id=$queryId["personId"];
            
$forename=$queryId["first_name"]." ".$queryId['surname'];
            echo 
'<option value="'.$id.'">'.$forename.'</option>';
        } 
// Ene of while 

echo '</select>'
OR:

PHP Code:
while($queryIds->fetchInto($queryId))
        {
            
$id=$queryId["personId"];
            
$forename=$queryId["first_name"]." ".$queryId['surname'];
            
$options.="<OPTION VALUE=\"$id\">".$forename."</OPTION>";
        } 
// Ene of while

echo '<select name="person">'.$options.'</select>'
CrazeDizzleD is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Populating drop down menu with MySQL
 

Thread Tools

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 Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12301 seconds with 12 queries