Page 1 of 1

Commas in variables

Posted: Thu May 24, 2007 2:33 pm
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.

Posted: Thu May 24, 2007 2:36 pm
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.

Posted: Thu May 24, 2007 2:52 pm
by bill1one
Like I said, it was a stupid question. That worked brilliantly.
Thanks.

Posted: Thu May 24, 2007 6:08 pm
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).