Seperate Switch Statments

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

Post Reply
flight_club
Forum Newbie
Posts: 3
Joined: Sat Apr 10, 2010 3:12 pm

Seperate Switch Statments

Post by flight_club »

Hi,
I'm somewhat of newb so please forgive me for my ignorance....

In any case, my site currently has a simple php switch statment in the middle of the index.php page which changes the body pages

Here is the code:

Code: Select all

<?php

$url=$_GET['url']; if (empty($url)) { $url='index'; } 

changelocation($url);

function changelocation($url) {

switch ($url) 

{ 

case 'index': 	

include ('main.html'); 

break; 

etc...
}}
?>
The issue is that I would like to have a differnt the header on each page (the purpose is to have different meta data for each page); however, I do not reallly have a clue about going about this as I already have one switch statement. Any help would be greatly appreciated.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Seperate Switch Statments

Post by requinix »

Yeah... Not enough information for us to help.

Kinda seems like you'll have to change the fundamental workings of your site, but just in case you don't, how about posting (a) the rest of the code, and (b) main.html?
lunarnet76
Forum Commoner
Posts: 67
Joined: Sun Apr 04, 2010 2:07 pm
Location: Edinburgh

Re: Seperate Switch Statments

Post by lunarnet76 »

hi,

you should simply do something like

Code: Select all

<?php

$url=$_GET['url']; if (empty($url)) { $url='index'; } 
$metaDescription='what i want';
changelocation($url);

function changelocation($url) {

switch ($url) 

{ 

case 'index':   
$metaDescription='what i want for the index';
include ('header.html'); // this file contains the html <head> part  
include ('main.html'); 

break; 

etc...
}}
?>
and then in your header.html have

Code: Select all

<head><meta name="description" content="<?php echo $metaDescription;?>" /></head>
flight_club
Forum Newbie
Posts: 3
Joined: Sat Apr 10, 2010 3:12 pm

Re: Seperate Switch Statments

Post by flight_club »

tasairis wrote:Yeah... Not enough information for us to help.

Kinda seems like you'll have to change the fundamental workings of your site, but just in case you don't, how about posting (a) the rest of the code, and (b) main.html?
Hi thanks for the reply I figured it out. For anyone else who has the issue I simply did the following:

Code: Select all


<?php

$url=((isset($_GET['url'])) ? $_GET['url'] : '');

ob_start();
$metadata = changelocation($url);
$content_for_page = ob_get_clean();

function changelocation($url) {

    switch ($url)

    { 
        default:

            include ('main.html');
            return '<meta name="keywords" content="words"/>';
            break;

etc...
}}
?>
Then in the <head>

Code: Select all

<?php echo $metadata ?>
</head>

In the body

Code: Select all

<?php echo $content_for_page; ?>
flight_club
Forum Newbie
Posts: 3
Joined: Sat Apr 10, 2010 3:12 pm

Re: Seperate Switch Statments

Post by flight_club »

lunarnet76 wrote:hi,

you should simply do something like

Code: Select all

<?php

$url=$_GET['url']; if (empty($url)) { $url='index'; } 
$metaDescription='what i want';
changelocation($url);

function changelocation($url) {

switch ($url) 

{ 

case 'index':   
$metaDescription='what i want for the index';
include ('header.html'); // this file contains the html <head> part  
include ('main.html'); 

break; 

etc...
}}
?>
and then in your header.html have

Code: Select all

<head><meta name="description" content="<?php echo $metaDescription;?>" /></head>

Thanks lunarnet as well
Post Reply