concatenate...how?in my case..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

concatenate...how?in my case..

Post by pleigh »

i'm having troulble concatenating my code....i want the firstname and last name to be concatenate...so far, no success...

Code: Select all

$pulldown .= "<option value=\"{$row['firstname']}\">{$row['firstname']}</option><br>";
i want to insert
a space first then
$row['lastname']
inside
<option value=\"{$row['firstname']}\">
thanks in advance... :)
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

explain more...
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

If you want to make a selection box populated by fullnames,
concatenate the firstname and lastname fields in you query

Code: Select all

$query = "SELECT id,concat(lastname,', ',firstname) as fullname FROM Names";
That will result to similar to this:
Dano, Harrison
Ramota, Maricar
Bilagot, Carmencita
Then use 'id' field, or something, as the value for your options and the concatenated names as the texts.

Code: Select all

while($data=mysql_fetch_array($result)){
    $id = $data['id'];
    $fullname = $data['fullname'];
    $str = "
    <option value='$id'>$fullname</option>";
}
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

i was able to retrieve the value of the firstname but in my case, i just want to add a space then concatenate the retrieved lastname within this code

Code: Select all

"<option value=\"{$row['firstname']}\">
im having confusion with the placement of the quotes'' and/or double quotes"" for concatenation

thanks:)
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

sorry if i misunderstood that.
use &nbsp; - no blank space.

Code: Select all

$str = "<option value=\"{$row['firstname']}&nbsp;{$row['lastname']}\">";
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

yup, its ok....:D...thanks...i also used your first code though...

Code: Select all

concat(lastname,', ',firstname) as fullname
thanks a lot.. :wink:
Post Reply