Jump to content

Archived

This topic is now archived and is closed to further replies.

lworks

Easy Navigation and $_GET.

Recommended Posts

I was wondering how to do something like this: tutorials.php?section=1&page=2 using a switch. I can get this: tutorials.php?section=1. Just don't know how to get the page part. Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
in your script use $_GET['section'] to get section and $_GET['page'] to grab the value of page

Share this post


Link to post
Share on other sites
Yea..some guy told me the same thing on an IRC channel. I still don't understand how to use it in a switch.

Share this post


Link to post
Share on other sites
you could go like this to define them:

[code]
if(!isset($_GET['section'])){ $section = 1; }else{ $section = $_GET['section']; }
if(!isset($_GET['page'])){ $page = 1; }else{ $page = $_GET['page']; }

switch($section){

//add other cases

case 'default':
something here
}
[/code]

then you can do the page you would do use in each section in your sql query's.

Share this post


Link to post
Share on other sites
Example:
[code=php:0]switch($_GET['section'])
{
    case 1:
        // do stufff for section 1
    break;

    case 2:
        // do stufff for section 2
    break;

    // other cases here
   
    // defualt case:
    default:
        // do something here if $_GET['section'] doesnt match any of the cases
    break;
}[/code]

Share this post


Link to post
Share on other sites
Actually, like if someone goes here: tutorals.php?section=1&page=2 .. now section 1 would be /tutorials/html/basics and page 2 would be /tutorials/html/basics-page-2.php. I don't understand how to get the page=2 into the URL..

[sub]if(!isset($_GET['section'])) {
$section = 1; }
else {
$section = $_GET['section'];
}
if(!isset($_GET['page'])) {
$page = 1;
}
else {
$page = $_GET['page'];
}
switch($section){
case '1':
include_once("/tutorials/html/basics/basics-THEPAGENUMBER.php");
break;
blah blah
}[/sub]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.