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
display two fields as one, in a pull-down menu
Old 12-13-2010, 01:17 PM display two fields as one, in a pull-down menu
Average Talker

Posts: 19
Trades: 0
I have a pull down menu in an HTML form. I want to populate that pull down with names from a database. I have it working pullin just the frist name, but I need it to pul both First and Last name from the database, and they are two different fields. here is what I have so far...

PHP Code:
<?php 
echo '<select name= "First_Name" , "Last_Name">';
while( 
$array mysql_fetch_assoc($result) ) {
     echo 
"<option value=\"{$array['value']}\">{$array['First_Name']}</option>\n";
}
echo 
'</select>';?>
This is working and pulling only the First Name into the pull down. I need it to pull the last name too, but I do not know how to code it to display both.

Please help.
lazerbrains is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-13-2010, 01:32 PM Re: display two fields as one, in a pull-down menu
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
$text_for_select = $array["First_Name"] . " " . $array["Last_Name"];
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE

Last edited by PaulW; 12-13-2010 at 01:33 PM..
PaulW is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 01:42 PM Re: display two fields as one, in a pull-down menu
Average Talker

Posts: 19
Trades: 0
Quote:
Originally Posted by PaulW View Post
$text_for_select = $array["First_Name"] . " " . $array["Last_Name"];
Nope. When I add what yo suggested:

PHP Code:
<?php 
echo '<select name= "First_Name" , "Last_Name">';
while( 
$array mysql_fetch_assoc($result) ) {
     echo 
"<option value=\"{$array['value']}\">{$array['First_Name'] . " " $array['Last_Name']}</option>\n";
}
echo 
'</select>';?>

</p>
It gives me this error:

Parse error: syntax error, unexpected '.', expecting '}' in /home5/windfal2/public_html/ledge/wp-content/themes/arras/letter.php on line 72

This being line 72:

PHP Code:
     echo "<option value=\"{$array['value']}\">{$array['First_Name'] . " " $array['Last_Name']}</option>\n"
lazerbrains is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 02:08 PM Re: display two fields as one, in a pull-down menu
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Check private messages
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE

Last edited by PaulW; 12-13-2010 at 02:11 PM..
PaulW is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 02:13 PM Re: display two fields as one, in a pull-down menu
Average Talker

Posts: 19
Trades: 0
Quote:
Originally Posted by PaulW View Post
Check private messages
Uh... I'm confused. Can you provide an example?
lazerbrains is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 02:16 PM Re: display two fields as one, in a pull-down menu
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Odd things going on when I type code Do the assignment inside the loop and follow it with the echo for the option line but use the variable $str in value and option display text -- no array references.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 02:23 PM Re: display two fields as one, in a pull-down menu
Average Talker

Posts: 19
Trades: 0
Quote:
Originally Posted by PaulW View Post
Odd things going on when I type code Do the assignment inside the loop and follow it with the echo for the option line but use the variable $str in value and option display text -- no array references.
I am not exactly sure what you want me to do. Currently this is working:

PHP Code:
<?php 
echo '<select name= "First_Name" , "Last_Name">';
while( 
$array mysql_fetch_assoc($result) ) {
    
     echo 
"<option value=\"{$array['value']}\">{$array['First_Name']}</option>\n";
}
echo 
'</select>';?>

Except for the fact that I can't get it to pull the last name. All I need is to be able to pull multiple fields into the select menu. Just First and Last Name. I am not sure what you are asking me to do or where. I am fairly new to PHP, I'm sorry.
lazerbrains is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 02:41 PM Re: display two fields as one, in a pull-down menu
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
My fault: I can't type code in here at the moment -- have a look at http://www.mredding.co.uk/pw2.html
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 02:52 PM Re: display two fields as one, in a pull-down menu
Average Talker

Posts: 19
Trades: 0
Aha!!!! Thank you so much!! That did the trick. Sorry I was so confused. I understand your previous posts now.

Now. I have one more thing I am wanting to do. When someone selects the name from the drop-down, i want the form to send to the address related to the selection. The emails are already in the Database. Any I idea how to send that address to the $to variable after the drop-down selection is made?
lazerbrains is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 02:56 PM Re: display two fields as one, in a pull-down menu
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Is there a unique id for each record?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 02:59 PM Re: display two fields as one, in a pull-down menu
Average Talker

Posts: 19
Trades: 0
Quote:
Originally Posted by PaulW View Post
Is there a unique id for each record?
Currently there is not. I created the database from a Excel Spreadsheet. Should I add one?
lazerbrains is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 03:14 PM Re: display two fields as one, in a pull-down menu
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Yes, (and pretty much always for a db table). Having done that, add the id to your initial db query and look at the link I sent before -- I've added some more below the first bit I gave.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 03:44 PM Re: display two fields as one, in a pull-down menu
Average Talker

Posts: 19
Trades: 0
Quote:
Originally Posted by PaulW View Post
Yes, (and pretty much always for a db table). Having done that, add the id to your initial db query and look at the link I sent before -- I've added some more below the first bit I gave.
When I do that, it creates two entries for each name in the database. Plus, I am not sure what you mean with the explode. how exactly does that work. And do I put that in the form?
lazerbrains is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 03:57 PM Re: display two fields as one, in a pull-down menu
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Re two entries: not sure what you're doing. (The problem if you don't have that primary key is that duplicate names can't be handled. ) When the form is submitted and you're doing whatever, put the explode in there, get the email from the database and send your email. (ie it isn't part of the form presentation, it's part of the form submission processing).
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 04:06 PM Re: display two fields as one, in a pull-down menu
Average Talker

Posts: 19
Trades: 0
Ok, so here is what I have so far. No longer pulling duplicates. (That was my fault)

PHP Code:
<?php 
echo '<select name= "First_Name" , "Last_Name">';
while( 
$array mysql_fetch_assoc($result) ) {
    
$text_for_select $array["First_Name"] . " " $array["Last_Name"]. " " $array["District"];
$value_for_select $array["First_Name"] . " " $array["Last_Name"] . "_" $array["id"];
echo 
"<option></option>\n";
echo 
"<option value=\"$value_for_select\">$text_for_select</option>\n"
}
echo 
'</select>';?>
Seems to be working just fine.


Now here is what my submission code looks like:

PHP Code:
<?php 
    
if($_POST){
    
$to $email;
    
$subject "WHAT SHOULD THIS BE";    
    
$message  =  "Date: $date\n\r".
                 
"Dear $First_Name$Last_Name,\n\r".
                 
"Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah..\n\r".
                
                
"Sincerely,\n".
                
"$name \n".
                
"$street \n".
                
"$city$zip \n".
                
"$email \\n".
    
$headers "From: $email";
    
mail($to$subject$message$headers);
    
// SUCCESS!
    
echo '<p class="notice">'.
        
'Thank you for your submission.  '.
          
'</p>';
    
// clear out the variables for good-housekeeping
    
unset($date,$legislator,$bill,$name,$street,$city,$zip,$email);
    
$_POST = array();
}
?>
Where would I place the explode code? And also what would I have the $to field equal to?
lazerbrains is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 04:34 PM Re: display two fields as one, in a pull-down menu
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
I need more Lemsip. In your original form, put the name attribute of the SELECT to something like "lazer_select", not what you currently have. Put the explode line at the start of the submission processing but where I've put value_for_select in the _POST reference, put lazer_select. Then you do the db lookup to get the email and name that goes with the id. Okay, I'm off to bed to feel fluey Good luck.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 05:45 PM Re: display two fields as one, in a pull-down menu
Average Talker

Posts: 19
Trades: 0
Hmm... anyone else have any ideas?
lazerbrains is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to display two fields as one, in a pull-down menu
 

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