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

Query string parameters in PHP

I'm trying to get multiple variables to work in the query string with PHP.

This is my code:

<?
$programme=$_GET['programme'];
switch ($programme) {
case 12578:
    include("http://mysite1.com/programme/TopGear");
    break;
case ER:
    include("http://mysite1.com/programme/ER);
    break;
default:
    echo "page not found!!!!";
}
$hPage=$_GET['hPage'];
switch ($hPage) {
case 1:
    include("page1.php");
    break;
case 2:
    include("page2.php");
    break;
case 3:
    include("page3.php");
    break;
default:
    echo "page not found!!!!";
}

?>


I'm trying to get the code so that the URL is similar to these: http://www.autoweek.nl/carbase_data.php?id=45405&cache=no
http://library.digiguide.com/lib/programmenextshowing/238308&hPage=2
where the query string has multiple parameters.

Feel free to improve my code, and I will test it out.
(Note that the URLs are mapped using my Apache's httpd-vhosts.conf, so they are local only to one machine, using VirtualHosts directive).

I am testing these before I manage to get a live site configuration working.

Also, if anyone knows how to, how do I rewrite the query string in the question mark to the ampersand?

Thanks! :)

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

Whitestream,

I'm trying to get the code so that the URL is similar to these: http://www.autoweek.nl/carbase_data.php?id=45405&cache=no http://library.digiguide.com/lib/programmenextshowing/238308&hPage=2 where the query string has multiple parameters.


Your url can't be similar to both of these examples. You must choose one or the other, and unless you want to make a lot of work for yourself, then use the first type.

The second type is generally used in MVC frameworks such as Zend or Cake and require Apache to run with mod-rewrite (or equivalent in other servers).

For your sample code, your url will be of the following format: http://www.mysite.xxx/mypage.php?programme=ER&hPage=2 .

Be aware that each $_GET element is a string, therefore you need to test with case 'ER': not case ER: .Airshow

Airshow
WiFi Lounge Lizard
Moderator
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You