PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Sun Nov 24, 2002 12:19 am
i foobared
Code: Select all
<?php
if($_GETї'page'] == "downloads"){
if(!isset($_GETї'download_id'])){
include 'downloads.php';
} else if($_GETї'download_id'] == "1"){
include 'games/1.php';
}
} else {
include('main.php');
}
?>
try that
Pocketx
Forum Commoner
Posts: 37 Joined: Fri Aug 23, 2002 9:54 pm
Post
by Pocketx » Sun Nov 24, 2002 10:39 am
IT WORKS!! THANKS MAN!
BTW, how do I add more pages like staff, reviews ect.?
Pocketx
Forum Commoner
Posts: 37 Joined: Fri Aug 23, 2002 9:54 pm
Post
by Pocketx » Sun Nov 24, 2002 12:57 pm
please help!
Pocketx
Forum Commoner
Posts: 37 Joined: Fri Aug 23, 2002 9:54 pm
Post
by Pocketx » Sun Nov 24, 2002 9:34 pm
Plz! Everything i try dosent work!
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon Nov 25, 2002 3:32 am
What have you tried - how does the code currently look? It's easier for us to help you edit your own code instead of writing code that may cause more problems when you try and integrate it.
Mac
Pocketx
Forum Commoner
Posts: 37 Joined: Fri Aug 23, 2002 9:54 pm
Post
by Pocketx » Mon Nov 25, 2002 11:14 am
Ive tryed to add an about page
Code: Select all
<?php
if($_GETї'page'] == "downloads"){
if(!isset($_GETї'download_id'])){
include 'downloads.php';
} else if($_GETї'download_id'] == "1"){
include 'games/1.php';
}
if($_GETї'page'] == "about"){
include 'about.php';
}
} else {
include('main.php');
}
?>
But dosent work
Pocketx
Forum Commoner
Posts: 37 Joined: Fri Aug 23, 2002 9:54 pm
Post
by Pocketx » Mon Nov 25, 2002 5:42 pm
HELP!! PLEASE THIS IS THE LAST TIME! JUST HELP ME AND ILl GET THE HECK OUT OF THIS PLACE... PLEASE HELP!
BigE
Site Admin
Posts: 139 Joined: Fri Apr 19, 2002 9:49 am
Location: Missouri, USA
Contact:
Post
by BigE » Mon Nov 25, 2002 11:24 pm
Try this code.
Code: Select all
<?php
if($_GETї'page'] == "downloads"){
if(!isset($_GETї'download_id'])){
include 'downloads.php';
} else if($_GETї'download_id'] == "1"){
include 'games/1.php';
}
elseif($_GETї'page'] == "about"){
include 'about.php';
}
} else {
include('main.php');
}
?>
Also, you don't need to post multiple times. We will help when and if we can.
Pocketx
Forum Commoner
Posts: 37 Joined: Fri Aug 23, 2002 9:54 pm
Post
by Pocketx » Thu Nov 28, 2002 9:33 pm
Thanks but it dosent work.. I get the same information as the index.php instead of the about.php page
BTW Sorry to post double times, Im desperate
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Fri Nov 29, 2002 2:00 am
It's probably because the elseif for the about page is within the if statement for checking if it's the download page - $_GET['page'] cannot equal both 'downloads' and 'about' so you'll always include main.php for when $_GET['page'] is equal to about (looking at indented code makes it much easier to spot this kind of thing).
So what you probably need to do is move that elseif statement so your code looks something like:
Code: Select all
<?php
if ($_GETї'page'] == 'downloads'){
if (empty($_GETї'download_id'])){
include 'downloads.php';
} elseif ($_GETї'download_id'] == 1){
include 'games/1.php';
}
} elseif ($_GETї'page'] == 'about') {
include 'about.php';
} else {
include 'main.php';
}
?>
Mac
Pocketx
Forum Commoner
Posts: 37 Joined: Fri Aug 23, 2002 9:54 pm
Post
by Pocketx » Fri Nov 29, 2002 2:34 pm
wow.. thanks.. it works!
MeOnTheW3
Forum Commoner
Posts: 48 Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB
Post
by MeOnTheW3 » Sat Nov 30, 2002 2:23 am
I think a SWITCH statement may be cleaner and easier to scale, in this case:
//- First just grab all the variables in a backward-compatible manner
Code: Select all
<?php
foreach($HTTP_GET_VARS AS $key => $val)
{
//- Variable variables
// The value of $key becomes the variable name by $$key
$$key = $val;
}
?>
//- Now all the query string variables are available by the name as passed.
// for example: ...php?page=about
// foreach is run
// NOW
// $page holds the value 'about'
The following code allows for easy scalability and readability.
Code: Select all
<?php
switch($page)
{
case 'downloads':
switch( isset($download_id) ? $download_id : 0 ) // allow for empty($download_id)
{
case 0:
include('./downloads.php');
break;
case 1:
include('./games/1.php');
break;
case 2:
include('./games/2.php');
break;
default:
include('./downloads.php'); // fail-safe;
break;
}
break;
case 'about'
include('./about.php');
break;
case 'news'
include('./news.php');
break;
default:
break;
}
?>
Pocketx
Forum Commoner
Posts: 37 Joined: Fri Aug 23, 2002 9:54 pm
Post
by Pocketx » Sat Nov 30, 2002 5:23 pm
Then if you would to add the main page it would be
Code: Select all
<?php
switch($page)
{
case 'downloads':
switch( isset($download_id) ? $download_id : 0 ) // allow for empty($download_id)
{
case 0:
include('./downloads.php');
break;
case 1:
include('./games/1.php');
break;
case 2:
include('./games/2.php');
break;
default:
include('./downloads.php'); // fail-safe;
break;
}
break;
case 'about'
include('./about.php');
break;
case 'news'
include('./news.php');
break;
default:
include('./main.php');
break;
}
?>
Right?
MeOnTheW3
Forum Commoner
Posts: 48 Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB
Post
by MeOnTheW3 » Sat Nov 30, 2002 5:26 pm
Yes, if you wish main.php to load in all other cases.
Worked for you?
Pocketx
Forum Commoner
Posts: 37 Joined: Fri Aug 23, 2002 9:54 pm
Post
by Pocketx » Sun Dec 01, 2002 5:37 pm
The code dosent work
Parse error: parse error in /mnt/host-users/pocketx/test/index.php on line 24
which is include('./about.php');