954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Trying to pass ampersand through query strings in URL

Thank you for the tutorial last time on query strings :)
It worked for me, this is my working query string:

<?
$i=$_GET['vehicle'];
switch ($i) {
case Chrysler:
    include("chryslernew.php");
    break;
case Chevrolet:
    include("chevnew.php");
    break; 
default:
    echo "include ("nopage.php")";
}
?>


However, I'm trying to get my PHP URLs with query strings that have multiple pages to look like this:

http://library.digiguide.com/lib/programmenextshowing/238308&hPage=3


I can get the question mark in query string URLs with no problem, but the ampersand has proven difficult for me to get right.
How would I be able to do this in PHP?

whitestream6
Junior Poster
174 posts since Nov 2008
Reputation Points: 15
Solved Threads: 0
 

& is the parameter separator, if you want to pass it as part of the string, use %26 instead.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

yes pritaeas is right

BzzBee
Posting Whiz
327 posts since Apr 2009
Reputation Points: 16
Solved Threads: 48
 

Thanks for that. Do I have to create a separate .htaccess or php file to get this to work?

I have http://www.mychevycars.com (virtual host)
and I want to split the pages (page1.php, page2.php) into:

http://www.mychevycars.com/aveo/3door&hPage=1 http://www.mychevycars.com/aveo/3door&hPage=2 http://www.mychevycars.com/aveo/3door&hPage=3


It isn't quite working.

whitestream6
Junior Poster
174 posts since Nov 2008
Reputation Points: 15
Solved Threads: 0
 

I'm still trying to figure this out... anyone got any advice?

whitestream6
Junior Poster
174 posts since Nov 2008
Reputation Points: 15
Solved Threads: 0
 

The query string starts after the "?" sign. The first variable must follow the "?" sign which indicates the end of the url path and start of query string variables. Further variables are then seperated by "&" sign. So to access hPage value fro the url it must be like this

http://www.mychevycars.com/aveo/3door?hPage=1 instead of http://www.mychevycars.com/aveo/3door&hPage=1

dasatti
Junior Poster in Training
57 posts since Dec 2008
Reputation Points: 10
Solved Threads: 5
 

What would I have to do to my query string?:

<?
$i=$_GET['carname'];
switch ($i) {
case 1:
    include("1.php");
    break;
case 2:
    include("2.php");
    break;
default:
    echo "page not found!!!!";
}
?>
whitestream6
Junior Poster
174 posts since Nov 2008
Reputation Points: 15
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You