Welcome to Gaia! ::

My Design :: Web and Graphic Design [HTML CSS PHP]

Back to Guilds

XHTML, CSS, jQuery, Javascript, PHP, mySQL, MORE! 

Tags: design, graphics, html, jquery, javascript 

Reply Tips/Tutorials
[PHP] multiple pages with one url

Quick Reply

Enter both words below, separated by a space:

Can't read the text? Click here

Submit

renlok

PostPosted: Tue Apr 03, 2007 3:11 pm


yeah i dont really know what to call it, but hey im board feel like writing about something.

lets start.

while surfing about the internet youve most proberly taken time to look at a URL. for example the url of this current page is http://www.gaiaonline.com/guilds/posting.php?mode=newtopic&f=85527
but also you could be on a page where the URL happens to be something like http://www.gaiaonline.com/guilds/posting.php?mode=edit&p=96927044.
From looking at these you sould notice that both these pages are run from the same webpage (posting.php) the strings after this tell the webapge to load up a particluar part being 'mode=edit&p=96927044' part or the 'mode=newtopic&f=85527' part.
This can be done with the use of the switch function the superglobal $_GET. (if you want to learn more about superglobals read up on it here).
The $_GET superglobal is used to find the values of the various variables following the page. Heres and example

$x=$_GET['x']
//if the url for this page is http://www.example.com/index.php?x=4 then the variable $x will now equel 4
?>

...that may of made sense ill change it later if it didnt but know onto the switch variable.
when the switch variables in use it sould look something like

switch($_GET[act])
{
case '';
echo "act is nothing";
break;

case '1';
echo "act is one";
break;
}
?>
now with that when $_GET[act] = nothing, act is nothing will show but when $_GET[act] = 1, act is one will show.

the break; tag is used to tell the browser when to stop reading if any one of the cases are correct if i didnt use break; if $_GET[act] = '' then both 'act is one' and 'act is nothing' would be displayed.

you can have as meny cases as you wish you can also put switches inside othe switches.

Hope that made some sense atleast anyway im board and tired now bye.
PostPosted: Sun Apr 08, 2007 6:58 pm


Thanks, was actually wondering how to do that.

My Documents
Captain


Shadow in the dark
Crew

PostPosted: Tue Apr 10, 2007 2:56 am


There's just one small thing you could change...

switch($_GET[act])
{
case '1':
echo "act is one";
break;

Default:
echo 'Act is nothing';
break;

}
?>


Default is basically the same as case '':

:3
PostPosted: Tue Apr 17, 2007 12:12 pm


yeah i know but i like to use case'': it makes me feel all fuzzy inside...=]]

My Documents
Thanks, was actually wondering how to do that.

Well, glad you found it helpful ^^

renlok


Zionna

PostPosted: Wed Apr 18, 2007 8:44 am


Quote:
switch($_GET[act])
{
case '1':
echo "act is one";
break;

Default:
echo 'Act is nothing';
break;

}
?>

Change this to
functuion MyFunction(){

echo "act is one"
//more code
}


switch($_GET[act])
{
case '1':
MyFunction()
break;

Default:
echo 'Act is nothing';
break;

}
?>


It tends to make everything a bit neater. Don't forget you can also pass vaules into functions.

e.g.
http://www.w3schools.com/php/php_functions.asp
function add($x,$y)
{
$total = $x + $y;
return $total;
}

echo "1 + 16 = " . add(1,16)
?>
PostPosted: Wed Apr 25, 2007 2:32 pm


hows that neater? O_o surly there exactly the same unless your planning on using the function again, which is very unlickly as id be an entire page storded in one function.

renlok


Zionna

PostPosted: Sat May 05, 2007 3:15 pm


renlok
hows that neater? O_o surly there exactly the same unless your planning on using the function again, which is very unlickly as id be an entire page storded in one function.


Neater/more organised/easier to read when compared to just writing the code in the switch statement.

Each function is a seperate page. Should also work with having combinations of functions being called.
PostPosted: Fri May 11, 2007 3:07 pm


oh right well if each functions on other pages that makes more sense, thats what i usually do. yeah it is alot easier to read and whatever.

renlok


Hoggs
Vice Captain

PostPosted: Thu Nov 29, 2007 3:10 am


Well why not just go all the way? rolleyes

class pageloader {


private function case1(){
echo "act is one";
//more code
}

public function load($act) {
switch($act) {
case '1':
$this->case1()
break;

Default:
echo 'Act is nothing';
break;
}
}
}

$page = new pageloader()
$page->load($_GET['act'])
?>


Reply
Tips/Tutorials

 
Manage Your Items
Other Stuff
Get GCash
Offers
Get Items
More Items
Where Everyone Hangs Out
Other Community Areas
Virtual Spaces
Fun Stuff
Gaia's Games
Mini-Games
Play with GCash
Play with Platinum