Jump to content


Photo

Easy Navigation and $_GET.


  • Please log in to reply
6 replies to this topic

#1 lworks

lworks
  • New Members
  • Pip
  • Newbie
  • 3 posts
  • LocationMississippi

Posted 02 October 2006 - 09:26 AM

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.
Part of the happiness of life consists not in fighting battles, but in avoiding them. A masterly retreat is in itself a victory.

- Norman Vincent Peale

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 02 October 2006 - 09:28 AM

in your script use $_GET['section'] to get section and $_GET['page'] to grab the value of page
follow me on twitter @PHPsycho

#3 lworks

lworks
  • New Members
  • Pip
  • Newbie
  • 3 posts
  • LocationMississippi

Posted 02 October 2006 - 09:32 AM

Yea..some guy told me the same thing on an IRC channel. I still don't understand how to use it in a switch.
Part of the happiness of life consists not in fighting battles, but in avoiding them. A masterly retreat is in itself a victory.

- Norman Vincent Peale

#4 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 02 October 2006 - 09:33 AM

you could go like this to define them:

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
}

then you can do the page you would do use in each section in your sql query's.
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 October 2006 - 09:34 AM

Example:
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;
}


#6 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 02 October 2006 - 09:39 AM

note that you don't have to use the break; for the default case.
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#7 lworks

lworks
  • New Members
  • Pip
  • Newbie
  • 3 posts
  • LocationMississippi

Posted 02 October 2006 - 09:41 AM

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..

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
}

Part of the happiness of life consists not in fighting battles, but in avoiding them. A masterly retreat is in itself a victory.

- Norman Vincent Peale




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users