PHP Newbie Question

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

User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

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
User avatar
Pocketx
Forum Commoner
Posts: 37
Joined: Fri Aug 23, 2002 9:54 pm

Post by Pocketx »

IT WORKS!! THANKS MAN!

BTW, how do I add more pages like staff, reviews ect.?
User avatar
Pocketx
Forum Commoner
Posts: 37
Joined: Fri Aug 23, 2002 9:54 pm

Post by Pocketx »

please help!
User avatar
Pocketx
Forum Commoner
Posts: 37
Joined: Fri Aug 23, 2002 9:54 pm

Post by Pocketx »

Plz! Everything i try dosent work!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

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
User avatar
Pocketx
Forum Commoner
Posts: 37
Joined: Fri Aug 23, 2002 9:54 pm

Post by Pocketx »

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
User avatar
Pocketx
Forum Commoner
Posts: 37
Joined: Fri Aug 23, 2002 9:54 pm

Post by Pocketx »

HELP!! PLEASE THIS IS THE LAST TIME! JUST HELP ME AND ILl GET THE HECK OUT OF THIS PLACE... PLEASE HELP!
User avatar
BigE
Site Admin
Posts: 139
Joined: Fri Apr 19, 2002 9:49 am
Location: Missouri, USA
Contact:

Post by BigE »

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.
User avatar
Pocketx
Forum Commoner
Posts: 37
Joined: Fri Aug 23, 2002 9:54 pm

Post by Pocketx »

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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

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
User avatar
Pocketx
Forum Commoner
Posts: 37
Joined: Fri Aug 23, 2002 9:54 pm

Post by Pocketx »

wow.. thanks.. it works!
MeOnTheW3
Forum Commoner
Posts: 48
Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB

Post by MeOnTheW3 »

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;

}
?>
User avatar
Pocketx
Forum Commoner
Posts: 37
Joined: Fri Aug 23, 2002 9:54 pm

Post by Pocketx »

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 »

Yes, if you wish main.php to load in all other cases.

Worked for you?
User avatar
Pocketx
Forum Commoner
Posts: 37
Joined: Fri Aug 23, 2002 9:54 pm

Post by Pocketx »

The code dosent work

Parse error: parse error in /mnt/host-users/pocketx/test/index.php on line 24

which is include('./about.php');
Post Reply