Jump to content

need help formatting php mysql output


BobH

Recommended Posts

I have a mysql database that has your typical data in it, ie. name address, etc.  The problem I am having is with the address.  The address is setup as a varchar with 200 as the length and the data is street, city, st, zip on 1 line.  I need to format the output with street on 1 line and city, st, zip on another.  I cannot change input format because of the way the program uses the address string to fetch the lat and lng before it writes it to the database.  Is there a way to add a line break or <br> to the address before it is written or change it after it is written using sql or php script or possible as I format the output?  The street, city, st, zip are separated by commas in the record.

 

Thanks in advance for all the reply's  :D

Link to comment
https://forums.phpfreaks.com/topic/213056-need-help-formatting-php-mysql-output/
Share on other sites

You really should change the db structure to save those address parameters in separate fields, but here is a quick fix:

list($street, $city, $state, $zip) = explode(',' $addressFromDB);

echo "$street<br />\n";
echo "$city, $state $zip";

Thanks for the quick reply and example.  I did some research on the explode() and I believe I can use it to either format the output or better yet create a new string before it is written to the database and get the desire out come.  As you can see I am still learning.  ;)

 

Thanks  :D

Thanks for the quick reply and example.  I did some research on the explode() and I believe I can use it to either format the output or better yet create a new string before it is written to the database and get the desire out come.  As you can see I am still learning.  ;)

 

Thanks  :D

 

Did you even try the sample code I provided? It used explode() as well as list() to populate the individual values into discrete variables. You can then output in any manner you wish such as the example I provided.

Thanks for the quick reply and example.  I did some research on the explode() and I believe I can use it to either format the output or better yet create a new string before it is written to the database and get the desire out come.  As you can see I am still learning.  ;)

 

Thanks  :D

 

Did you even try the sample code I provided? It used explode() as well as list() to populate the individual values into discrete variables. You can then output in any manner you wish such as the example I provided.

 

Yes I will use it but am at work now.  A big thanks.  I meant after your mentioned explode(), I did a little research as to how it worked.  Looks like your example will work just fine..tks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.