Help - Search - Members - Calendar
Full Version: PHP Switching
Invision Power Services > Community Forums > Community Web Design and Coding
Reado
I've already read the tutorial on the PHP site but it only tells me half of what I want to know.

I'm trying to use the following address navigation:
http://mydomain.com/index.php?cat=1&subcat=2

I can get the first part (before the &) to work, but it's the part after that I don't know the code for.

Can anyone help?

I'm using the following code already:

CODE
<?php
switch ($_GET['cat']) {
 case "1": $inc = './page1.php';
 break;
 default: $inc = './home.php';
 break;
    }
    include ($inc);
?>


Thanks.
Rikki
It's the same, you just use $_GET['subcat']; instead.
Reado
Could you give me an example please as I don't know where to put it.
_
You could have something in [for instance, page1.php]:

CODE
switch($_GET['subcat'])
{
       case 'hello':
       echo "hello";
       break;
}
Reado
This will not work with template style navigation, and to be honest, I've just tried it and it doesn't!

If I have:
http://mydomain.com/index.php?cat=1&subcat=2
http://mydomain.com/news.php?cat=1&subcat=2
http://mydomain.com/contact.php?cat=1&subcat=2

This won't work as all 3 pages are linked into the same template.

Can I not have a 'case' under another 'case'? Such as:
case "1": $inc = './home/page1.php';
case "2": $inc = './home/page1_2.php';
Buztin
why use a switch ... just use this...

CODE
$page_array = array();

$page_array["c1"] = "page1.php";
$page_array["c1s1"] = "page1_1.php";
$page_array["c1s2"] = "page1_2.php";
$page_array["c1s3"] = "page1_3.php";

$page_array["c2"] = "page2.php";
$page_array["c2s1"] = "page2_1.php";
$page_array["c2s2"] = "page2_2.php";
$page_array["c2s3"] = "page2_3.php";

if (isset($_GET['subcat']) and $_GET['subcat'] != "")
{
  $inc = './home/' . $page_array['c' . $_GET['cat'] . 's' . $_GET['subcat']];
}
else
{
 $inc = './home/' . $page_array['c'.$_GET['cat']];
}

include ($inc);
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.