Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

format mysql output based on content

Status
Not open for further replies.

Donalo

Technical User
Aug 14, 2001
10
GB
I have an address book in Mysql with the name row containing the surname, firstname format. Can somebody explain how to format the ouput into two by splitting the name row by where the comma "," is? I've also got an address field with each line seperated by commas, i guess the solution would apply to that too, although it could be up to 4 or 5 lines?? Thanks in advance..
 
PHP functions are named very well. if you want to split a string by some character, the function is split();


Let's assume $row[name] is "Pan, Peter".
Code:
$newArray = split(',',$row[name]);
The yielded result is an array with as many elements as there are strings separated by commas:
$newArray[0] will be "Pan";
$newArray[1] will be "Peter"

The separator is removed.
If your address field has 5 lines, there will be 5 elements, if there are 4 lines separated by commas, there will be 4 elements.

From a database prospective and for clean data handling it is advisable to split distinctive fields in their own column. That makes searching and indexing on each of the distinct entities possible.
 
Cheers mate, that's brilliant. Answers all my questions and more!

nice one.

D [afro]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top