Using $_GET

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AK123
Forum Newbie
Posts: 1
Joined: Wed Sep 08, 2010 12:25 pm

Using $_GET

Post by AK123 »

Hello,

I am trying to use the $_GET command to build my webpages, however on the tutorial page I would like to put another $_GET command inside the first..

For example: index.php?section=tutorial&viewing=18-classes_or_ids

How do I create the tutorial&viewing variable inside of the section variable?

Here is my code at the moment:

Code: Select all

<?php
$section = $_GET['section'];
switch ($section)
{
	case "home":
	include("home.html");
	break;
	case "register":
	include("register.html");
	break;
	case "tutorials_home":
	include("tutorial.html");
	break;
	default:
	include("home.html");
	break;

$tutorials = $_GET['tutorial&viewing'];
switch ($tutorials)
{
	case "18-classes_or_ids":
	include("cassesorids.html");
	}
}
?>
Thanks
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Using $_GET

Post by AbraCadaver »

You don't. Try another variable. Also, the & is special in a URL so you need to encode it:

Code: Select all

$url = "index.php?section=" . urlencode('tutorial&viewing') . "subsection=18-classes_or_ids";
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Using $_GET

Post by califdon »

AK123 wrote:Hello,

I am trying to use the $_GET command to build my webpages, however on the tutorial page I would like to put another $_GET command inside the first..

For example: index.php?section=tutorial&viewing=18-classes_or_ids

How do I create the tutorial&viewing variable inside of the section variable?

Here is my code at the moment:

Code: Select all

<?php
$section = $_GET['section'];
switch ($section)
{
	case "home":
	include("home.html");
	break;
	case "register":
	include("register.html");
	break;
	case "tutorials_home":
	include("tutorial.html");
	break;
	default:
	include("home.html");
	break;

$tutorials = $_GET['tutorial&viewing'];
switch ($tutorials)
{
	case "18-classes_or_ids":
	include("cassesorids.html");
	}
}
?>
Thanks
I think you are confusing what index.php?section=tutorial&viewing=18-classes_or_ids means. The ampersand (&) character separates key-value pairs in a URI, so that is specifying 2 variables and their values:
section=tutorial
viewing=classes_or_ids

You recover those values in PHP like this:

Code: Select all

...
$section = $_GET['section'];
$tutorials = $_GET['viewing'];
...
Post Reply