trim function not working

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
mhillman
Forum Newbie
Posts: 3
Joined: Fri Jun 14, 2002 9:25 am

trim function not working

Post by mhillman »

The intent is to show a list of members of a sorority alumni association, by combining their last name when they pledged the sorority and their last name now into a value called "fullname". The display page shows " , firstname", rather than "fullname, firstname"

I am new to php. Can someone please review this code and tell me what I am doing wrong?

$sql = "SELECT id, trim(concat(ln_then,' ',ln_now)) as fullname, firstname
FROM $table_name
ORDER BY fullname
";

$result = @mysql_query($sql,$connection) or die("Couldn't execute query.");

$contact_list = "<ul>";

while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$firstname = $row['firstname'];
$fullname = $fullname['fullname'];

$fullname = trim($fullname);


$member_list .= "<li><a href=\"show_member_public.php?id=$id\">$fullname, $firstname</a>";
}

$member_list .= "</ul>";
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try,

Code: Select all

$sql = "SELECT id, CONCAT(ln_then,' ',ln_now) AS fullname, firstname FROM $table_name ORDER BY fullname"; 
$result = @mysql_query($sql,$connection) or die('Couldn't execute query.<br />'.mysql_error());
and change

Code: Select all

$fullname = $fullname&#1111;'fullname'];
to

Code: Select all

$fullname = $row&#1111;'fullname'];
It's easier to help if you tell us what's going wrong and what the error messages are (if there are any).

Mac
mhillman
Forum Newbie
Posts: 3
Joined: Fri Jun 14, 2002 9:25 am

the problem is:

Post by mhillman »

when the page displays, I see:

, firstname

instead of
fullname, firstname

I will try your modifactions. thanks for the quick reply
mhillman
Forum Newbie
Posts: 3
Joined: Fri Jun 14, 2002 9:25 am

solved

Post by mhillman »

I just changed
$fullname = $fullname ["fullname']
to
$fullname = $row['fullname'];

:oops: Thats what's known as a "duhh!"

Thanks for your quick help.
Post Reply