Forum Moderators: coopster

Message Too Old, No Replies

Replacing text

State names

         

smatts9

12:00 am on Mar 9, 2006 (gmt 0)

10+ Year Member



I store the state names in a db in their short form, such as Nebraska, I ahve it stored as NE. When calling a page, it has

url.com/page.php?state=NE

So it goes to that page, but I use the state name in the database which is also NE, so I use something like:

<? echo ($statename);?> Page

It shows "NE Page"
I want it to show "Nebraska Page"

I have been trying to figure out str_replace, and can't seem to get it to work. Or if there is another quicker way, any advice is appreciated.

Thanks for the help.

jatar_k

1:00 am on Mar 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what about having a column/table that maps the short (ie NE) to the fullnames (ie Nebraska)

smatts9

1:11 am on Mar 9, 2006 (gmt 0)

10+ Year Member



I don't think I understand. You mean make another database column for the state fullname and use that to display instead? Going that way would be quite a lot of work..? Please Elaborate on what you mean, Thank you!

jatar_k

1:24 am on Mar 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



In databases I have used if I needed to use both short and long names then I have mapped a table for that

store in user table NE

select longname from states where shortname='NE';

something like that, as long as your state short forms are normalized then it shouldn't be an issue

you could also join them so that when you select you could get the fullname, though this would have to be tested for performance impact.

m4tt

2:24 am on Mar 9, 2006 (gmt 0)

10+ Year Member



I would create a new line in your table and have it as
stateName. I have had the same problem and that is how I got around it. I then changed the get to the stateName and it worked like this:

locator.php?stateName=