Current location: Hot Scripts Forums » Programming Languages » PHP » $_GET variable from previous page!


$_GET variable from previous page!

Reply
  #1 (permalink)  
Old 07-26-04, 06:50 PM
truesilentassassin truesilentassassin is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
$_GET variable from previous page!

Hello,

I have a page called city.php which displays a list of major cities based on the state selected. I have an index.html page which has all the state names with links like city.php?state=California, city.php?state=Texas, and so on.

Since the link is setup this way, I am able to query for the user selected state by using state = '{$_GET['state']}'

Using $_GET I am able to display cities based on the state clicked by user.

I have a page called category.php and I do the same thing.

I list categories based on city clicked, the problem here is all cities have the same categories (about 40 categories) so all I do on this page is select * from category;

On this page I give link for each category as: categorydetails.php?category=Automobile and so on.

Doing this, I am able to display details on the category selected by user.

But my selection is based on the category (using $_GET)

I also want to use city in my query.

What I mean is: I want to display categories for the category selected by the user in category.php page and ONLY FOR THE CITY SELECTED BY THE USER IN THE CITY.PHP page.

This is where I have trouble.

I don't have the city value stored anywhere to use it on categorydetails.php page.

I am able to use city on the category.php page using $_GET, but not on categorydetails.php page.

Is there a way that I could use the value of city from the category.php page in my categorydetails.php query page?

Now the link for each category is setup like this: categorydetails.php?category=$category

I also tried:
categorydetails.php?category=$category&city=$city

and used city in my query in categorydetails.php page, but I dont get any results nor errors.

Please help me.

Regards,
Reply With Quote
  #2 (permalink)  
Old 07-26-04, 07:59 PM
jasong jasong is offline
Wannabe Coder
 
Join Date: Feb 2004
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Couldnt you use hidden fields in category.php?
Reply With Quote
  #3 (permalink)  
Old 07-26-04, 08:18 PM
truesilentassassin truesilentassassin is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Space between Link in PHP

Hello,
Here is my situation:

I have a page called category and I pull several categories from my database.

Each category is linked this way:

categorydetails.php?category=$category&city=$city

$category and $city is taken using $_GET

The script perfectly works for categories and cities with a name without space.

What I mean is, if I select Sacramento, the query works well.

If I select Los Angeles, my link looks like this:
categorydetails.php?category=Automobile&city=Los

It excludes "Angeles". I am assuming it has to do something with the space in the middle.

How do I over come this.

I link should actually look like this:
categorydetails.php?category=Automobile&city=Los Angeles.

Help me.

Regards,
Reply With Quote
  #4 (permalink)  
Old 07-26-04, 08:37 PM
truesilentassassin truesilentassassin is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Space between Link in PHP

Hello,
Here is my situation:

I have a page called category and I pull several categories from my database.

Each category is linked this way:

categorydetails.php?category=$category&city=$city

$category and $city is taken using $_GET

The script perfectly works for categories and cities with a name without space.

What I mean is, if I select Sacramento, the query works well.

If I select Los Angeles, my link looks like this:
categorydetails.php?category=Automobile&city=Los

It excludes "Angeles". I am assuming it has to do something with the space in the middle.

How do I over come this.

I link should actually look like this:
categorydetails.php?category=Automobile&city=Los Angeles.

Help me.

Regards,
Reply With Quote
  #5 (permalink)  
Old 07-26-04, 08:58 PM
kvnband kvnband is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 242
Thanks: 0
Thanked 0 Times in 0 Posts
str_replace(" ", "%20", "$city")

That will replace the spaces with %20, which is identical to a space in a URL.

Kevin
Reply With Quote
  #6 (permalink)  
Old 07-26-04, 08:59 PM
kvnband kvnband is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 242
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry
PHP Code:

categorydetails.php?category=$category&city=str_replace(" ""%20""$city"

Pretty sure that'll work in your case
Reply With Quote
  #7 (permalink)  
Old 07-26-04, 09:55 PM
mikaelf mikaelf is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: php[dot]net
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
You'd better use PHP built-in function: urlencode and urldecode to safely cast your url.
PHP Code:

print "<a href=\"".urlencode("categorydetails.php?category=$category&city=$city")."\">Go to details</a>"
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
Sending a variable to a page redirected to with header() ? Frank PHP 3 05-19-04 08:02 AM
page browsing problem mivec PHP 3 04-17-04 03:43 AM
how to read a web page content to a variable? wings01234 JavaScript 4 01-13-04 08:27 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 04:14 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.