Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-24-2003, 04:13 PM   PM User | #1
martincrumlish
New to the CF scene

 
Join Date: Oct 2002
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
martincrumlish is an unknown quantity at this point
HELP: Passing value from DB in URL - spaces problem

Hi,

I have a problem. I have written a web app that takes results from an Informix DB. this DB is part of a legacy system and as such, I cant change the data in it. i am only writing something that outputs the data.

One of the DB fields holds placenems and these in some cases are two words ie: San Diego. Now, there is a second page which produces further results depending on the placename. I pass the placename value to the next page in the URL but, and here's the problem:

Normally, I pass the value like so: link.php?name=$placename If the placename is Dublin then the link would be
PHP Code:
link.php?name=Dublin 
However, if the placename is San Diego this becomes
PHP Code:
link.php?name=San Diego 
When I try to pass this in the URL it doesnt work and only passes it like this:
PHP Code:
link.php?name=San 
As such, this messes up the query that relies on the $name value on the link.php page.

Anyone got any ideas?

Thanks,
Martin
__________________
Visit my online portfolio
martincrumlish is offline   Reply With Quote
Old 01-24-2003, 04:29 PM   PM User | #2
Jeewhizz
Regular Coder


 
Join Date: May 2002
Location: London, England
Posts: 369
Thanks: 0
Thanked 0 Times in 0 Posts
Jeewhizz is an unknown quantity at this point
THere is a PHP function that does this - it'll chuck %20 instead of a space, which the browser will read as a space...

and that function is.. urlencode() - www.php.net/urlencode

Jee
__________________
Jeewhizz - MySQL Moderator
http://www.sitehq.co.uk
PHP and MySQL Hosting
Jeewhizz is offline   Reply With Quote
Old 01-24-2003, 04:54 PM   PM User | #3
martincrumlish
New to the CF scene

 
Join Date: Oct 2002
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
martincrumlish is an unknown quantity at this point
Thanks.

Because of some of the characters in my query, urlencode doesnt work properly so I used this instead:
PHP Code:
$string ereg_replace (" ""%20"$string); 
This works apart from one thing.....the value in the DB also has a load of spaces after the last letter of the word.

ie: "SAN DIEGO "

when I use:
$string = ereg_replace (" ", "%20", $string);

this would give "SAN%20DIEGO%20%20%20%20%20%20%20%20%20%20" Is there away to replace the first space and then trim off all the rest?
__________________
Visit my online portfolio
martincrumlish is offline   Reply With Quote
Old 01-24-2003, 05:11 PM   PM User | #4
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
Use trim()
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:57 AM.


Advertisement
Log in to turn off these ads.