2005-10-12, 07:27 PM
In this tutorial I will explain how to make use the switch statement and function.
This script is for a personal site, it needs more code to be used in mybb.
Note: everything will be in one file.
Save as test.php
See $_GET['action'] What this will is add ?action after the php name (test.php?action). If you would like it to have test.php?lala just replace "action" with "lala".
Notice index(); This is being called by function index()
Now I'll show you how to get another page
Notice this section case "otherpage": This is put ?action=otherpage in the url. You can change the name to whatever you prefer.
If I wanted to change it to my name then I just do case "harmor":
Below the "case" I am calling a function with otherpage();
You can change the name of this as well just make you have the (); at the end and you rename the function it's calling. In this case it's calling function otherpage()
Here is the whole thing
This script is for a personal site, it needs more code to be used in mybb.
Note: everything will be in one file.
Save as test.php
<?php
switch($_GET['action'])
{
default:
index();
}
function index()
{
echo "Text goes here";
}
See $_GET['action'] What this will is add ?action after the php name (test.php?action). If you would like it to have test.php?lala just replace "action" with "lala".
Notice index(); This is being called by function index()
Now I'll show you how to get another page
<?php
switch($_GET['action'])
{
case "otherpage":
otherpage();
break;
default:
index();
}
function index()
{
echo "Text goes here <a href='test.php?action=otherpage'>";
}
function otherpage()
{
echo "This is my other page";
}
?>
Notice this section case "otherpage": This is put ?action=otherpage in the url. You can change the name to whatever you prefer.
If I wanted to change it to my name then I just do case "harmor":
Below the "case" I am calling a function with otherpage();
You can change the name of this as well just make you have the (); at the end and you rename the function it's calling. In this case it's calling function otherpage()
Here is the whole thing
<?php
switch($_GET['action'])
{
case "otherpage":
otherpage();
break;
default:
index();
}
function index()
{
echo "Text goes here <a href='test.php?action=otherpage'>Other Page</a>";
}
function otherpage()
{
echo "This is my other page <a href='test.php'>Home</a>";
}
?>