PHP pulling content into master php index

Hello thank you for visiting my thread your helps is appreciated.

First of all I am leaning how to put my site together using php and I am working off the following tutorial:
http://m.alistapart.com/articles/phpcms/
I am currently stuck on paragraph “Switching content with PHP variables”
What I seem to be doing doesn’t seem to be working. I am trying to pull up content into the body of my master php file.

In the tutorial it says:

The menu will stay the same for every page, so we can keep the menu.php hardcoded, but as the body will be changing we’ll need to use a variable to give us a way to reference these changes dynamically.

PHP variables can be identified by their preceding $. So, we can change the hard-coded body.html into a dynamically updateable variable by coding it as $page.html. Every reference to $page will be replaced by whatever we set the variable $page to be.

Change the body reference to:

<?php @ require_once ("$page.html"); ?>
We’ll set the variable in the query string (everything that comes after the "?") of the url: template.php?page=babeuf.

The code above will replace any instance of $page with babeuf, so $page.html becomes babeuf.html. If we want to call picasso.html into that same template, we would set the Picasso link in our menu to template.php?page=picasso."

So I changed my body.html to $page.html and tried to include it into my page but when I included it it doesn’t seem to be pulling up content And changes/interfere with my layout, can someone help me figure out the problem?

Am I supposed to set any links in my menu.php to " index.php?page=picasso. " or “index.php?page=picasso.html or. PHP?”

Also can some please clarify how to call the variable page and how the variable page changes into the page you want?
My page can be found at www.thegrid.x10.bz.

Thank you very much for any help!

index.php?page=picasso is the normal method, i use it constantly.

on the index page content area, you’d put a switch, something like
[php]
if(!empty($_GET[‘page’])) {
switch($_GET[‘page’]) {
case ‘picasso’:
include ‘picasso.html’;
break;
}
}
[/php]

Thank you for your response, so from my understanding index.PHP?page=picasso would be what a link in my menu would say and there is no extension of php or html? But in the next line if Picasso link is clicked on then case is Picasso and it will include Picasso html or php? Is that right?

If I am wrong can you explain the meaning of the lines of code that you posted what each line does or tells the browser? I am not well seasoned to php.

The first line is saying if content is empty pull up ‘page’ however is the $_get a command code or a variable page?
And what does “case” do?
Thank you

ok, here we go

The link would be Picasso

Then we have the php portion
[php]
if(!empty($_GET[‘page’])) {
switch($_GET[‘page’]) {
case ‘picasso’:
include ‘picasso.html’;
break;
}
}[/php]

if(!empty($_GET[‘page’])) { looks to see whether $_GET contains any information

case ‘picasso’ is a place holder, there has to be one for each link. The include can import just about any file (php, html, etc)

Okay let’s. See if I’ve got it, I’m doing a new about page :
In my menu.PHP my link would be <a href='index.PHP?page=about>about page
Then in my index.PHP put:
[php]
if(!empty($_GET[‘page’])) {
switch($_GET[‘page’]) {
case ‘about’:
include ‘about.html’;
break;
}
}[/php] is this correct?

But if I want the default page to be news.html and added more links to my menu.PHP such as abut and contact then would I put :
[php]
if(!empty($_GET[‘news.html’])) {
switch($_GET[‘page’]) {
case ‘picasso’:
include ‘picasso.html’;
case ‘about’:
include 'about.html;
case ‘contact’:
include 'contact.html
break;
}
}[/php]?

Thank you for your patience!

Oops I missed some characters in the last post, stupid android, is there an edit post in the forum?

There is, but its only for a short time after submission. You got it, after the last case, add default:, or add an else { after the last }

Is $page the same thing as $get? And what do these files look like?

[php]
if(!empty($_GET[‘news.html’])) {
switch($_GET[‘page’]) {
case ‘picasso’:
include ‘picasso.html’;
case ‘about’:
include 'about.html;
case ‘contact’:
include ‘contact.html’;
break;
Default:
Include ‘news.html’;
}
}[/php]

Or
[php]
if(!empty($_GET[‘news.html’])) {
switch($_GET[‘page’]) {
case ‘picasso’:
include ‘picasso.html’;
case ‘about’:
include 'about.html;
case ‘contact’:
include ‘contact.html’;
else {
include(‘news.HTML’);
}
}
} break;
[/php]

Right?
What is the ‘page’ beside switch calling up or do?

it would be
[php]
if(!empty($_GET[‘page’])) {
switch($_GET[‘page’]) {
case ‘picasso’:
include ‘picasso.html’;
break;
case ‘about’:
include ‘about.html’;
break;
case ‘contact’:
include ‘contact.html’;
break;
default:
include ‘news.html’;
break;
}
} else {
include ‘news.html’;
}[/php]

basically, the if(!empty()) is looking to see if there’s any data contained in the GET array and if there is, move onto the switch, if not, then display news.html. The default case is there so that when there is data in the GET array, it’ll still display news.html, since data isn’t overwritten until the next link is clicked on.

“page” would be the identifier, i.e., whatever is after the question mark in the url (?page = something).

Hmmm I don’t know where my error is…

This is my current code for my page… for some reason there is something in the code that is messing up the layout when I add the php include for pulling the content in. I can’t figure out why. I think the include for the menu is fine. And I think I’m missing the array, and I’m not sure what it should be named or what it should look like… :S please advise! I’m a little confused.

[code]

|| +* TITLE*+||
<?php @ require_once("includes/nav.php");?>

Location

Portage Avenue
Winnipeg, MB RX1 1X1
Canada

Welcome

Welcome to the Grid : Games, Toys & Comics

<?php @ require_once ("$page.html"); ?>
<?php @ require_once ("$page.html"); ?> if(!empty($_GET['page'])) { switch($_GET['page']) { case 'home': include 'home.html'; break; case 'about': include 'about.html'; break; case 'contact': include 'contact.html'; break; case 'picks': include 'picks.html'; break; case 'reviews': include 'contact.html'; break; case 'items': include 'items.html'; break; case 'deal': include 'deal.html'; break; default: include 'news.html'; break; } } else { include 'news.html'; }

hjgj

test

some sentences
webmistress.

Credits and Copyrights

geresfsdbgds


© The Grid © CB

Featured Item

Featured Links

» Link Here
» Link Here
» Link Here
» Link Here

Events

THE GRID GRAND OPENING - 2012
Saturday, xx, 2012
SALE Hot Dogs, Hamburgers, Chips & Drinks
Prizes

The Grid: Games, Toys & Comics © The Grid

[/code]

and this is currently my menu.php include I think the code here seems to be okay.

[code]

Content

» GRID ONLINE STORE


» Home

» Items We Carry

» Deal of the Week

» Staff Picks

» Product Reviews

» The Grid Community

» The Best Of...

» About Us

» Contact

[/code]

the php is wrong
[php]

<?php require_once ("page.html"); if(!empty($_GET['page'])) { switch($_GET['page']) { case 'home': include 'home.html'; break; case 'about': include 'about.html'; break; case 'contact': include 'contact.html'; break; case 'picks': include 'picks.html'; break; case 'reviews': include 'contact.html'; break; case 'items': include 'items.html'; break; case 'deal': include 'deal.html'; break; default: include 'news.html'; break; } } else { include 'news.html'; }[/php] and » Deal of the Week

is wrong, should be » Deal of the Week

The best way to figure out layout issues is to look at the html output from view source, or if you're using firefox, get a plugin called firebug.
Sponsor our Newsletter | Privacy Policy | Terms of Service