Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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: 93
Trades: 0
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?

Last edited by drew22299; 06-27-2008 at 11:54 AM..
drew22299 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-27-2008, 03:26 PM Re: Populating drop down menu with MySQL
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
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>"
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

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: 71
Trades: 0
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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.31192 seconds with 12 queries