Page 1 of 1

concatenate...how?in my case..

Posted: Wed Jul 13, 2005 1:53 am
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... :)

Posted: Wed Jul 13, 2005 2:02 am
by harrisonad
explain more...

Posted: Wed Jul 13, 2005 2:13 am
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>";
}

Posted: Wed Jul 13, 2005 2:20 am
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:)

Posted: Wed Jul 13, 2005 2:23 am
by harrisonad
sorry if i misunderstood that.
use &nbsp; - no blank space.

Code: Select all

$str = "<option value=\"{$row['firstname']}&nbsp;{$row['lastname']}\">";

Posted: Wed Jul 13, 2005 2:31 am
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: