Forum Moderators: coopster
<?php
function viewdoSection($do)
{
switch($do) {
case 'home':
$section = 'home';
break;
default:
$section = false;
break;
}
return $section;
}
if(!empty($_GET['do']))
$section = viewdoSection($_GET['do']);
if (isset($section) && $section == 'home') {
print "<p>Print out some home section text.</p>";
} else {
print "<p>Just Information that gets shown if all other do checks fail.</p>";
}
?>
I can get the index.php?do=home to work but then is it possible to go even further so the url might look something like this: index.php?do=home:1 or index.php?do=home:2 or something like that? Cause I'm trying to draw information from the sql database and I have like 3 pages in one already but I want to be able to display different things one each the home:1 and home:2 page. I think this is called urlencode(); but I don't really understand it.
If anyone understands this can you please help me!
<?phpfunction viewdoSection($do) {
switch ($do) {
case 'home':
$section = 'home';
break;
default:
$section = FALSE;
break;
}
return $section;
}if (isset($_GET['do']) && !empty($_GET['do'])) {
viewdoSection($_GET['do']);
if ($section == 'home') {
if (isset($_GET['sub']) && !empty($_GET['sub'])) {
switch ($_GET['sub']) {
// handle $_GET['sub'] however you wish
}
} else {
echo('some error message');
}
} else {
echo('some error message');
}
}?>
I didn't see anything in your code that would handle the other part of the URL, but this should give you a general idea.
If you absolutely need the type of URL your originally asked about, a comma instead of a colon would work very well. I personally prefer slashes for the search-engine-friendliness.
Anyway, that was just an example; it probably won't help you much in the way of getting some working code. $_GET is quite simple. If you give the URL as index.php?foo=bar the variable $_GET['foo'] will be set to "bar" in your script.
For multiple values: index.php?foo=bar&yes=no would set $_GET['foo'] to "bar" and $_GET['yes'] to "no".
You can use a $_GET variable as you would any other variable. Knowing that, you should be able to apply your knowledge of control structures to getting exactly the effect you want.