BobH Posted September 10, 2010 Share Posted September 10, 2010 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 Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 10, 2010 Share Posted September 10, 2010 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"; Quote Link to comment Share on other sites More sharing options...
litebearer Posted September 10, 2010 Share Posted September 10, 2010 you could use EXPLODE (use the comma as the delimiter) to create an array. 0 = street, 1 = city, 2 = st, 3 = zip. then format as you chose (ie street on line 1, city comma state zip on line 2) slow typist here Quote Link to comment Share on other sites More sharing options...
BobH Posted September 10, 2010 Author Share Posted September 10, 2010 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 Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 10, 2010 Share Posted September 10, 2010 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 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. Quote Link to comment Share on other sites More sharing options...
BobH Posted September 10, 2010 Author Share Posted September 10, 2010 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 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.