Commas in variables

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
bill1one
Forum Newbie
Posts: 8
Joined: Thu May 24, 2007 2:12 pm

Commas in variables

Post by bill1one »

I know this is a stupid and elementary question, but I've done several Google searches and can't find any answers.
I am using a name from a MySQL database as a variable. The name is formated as "Lastname, Firstname".
The php code I'm using is

Code: Select all

echo "<a href=SearchDetail.php?ID=" . $row[$i] . "&Name=" . $row[$i+1] . ">" . $row[$i] . "</a>";

...where $row[$i] is referencing the name.
If the name in the database is "Smith, John" and that variable is passed, the result I get for the Name is

Code: Select all

Smith,
How do I get PHP to keep the information following the comma?
Thank for your patience as I am new to PHP & MySQL.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You're missing quotes around the value of the attribute "href."

rawurlencode() may be of interest too, but quotes must be there first and foremost.
bill1one
Forum Newbie
Posts: 8
Joined: Thu May 24, 2007 2:12 pm

Post by bill1one »

Like I said, it was a stupid question. That worked brilliantly.
Thanks.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

May I ask why you have one field name containing two separate pieces of data? It might be easier to have a first name field and last name field and build the name string however you want it built based on the end user desire (Last, First... First Last... F. Last... Last, F. etc).
Post Reply