943,447 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 9972
  • PHP RSS
Oct 12th, 2004
0

Multiple PHP INCLUDES

Expand Post »
I constantly use the PHP INCLUDES feature on my site, & recently ran into a problem that I'm not sure is solveable at the moment & I'm hoping someone will have a solution.

I'm aware that PHP INCLUDES is ususally for content that you want to keep constant over many pages, but I use it for modifying the main content of my site.

My home page is basically static (and constant throughout the entire site) except for the main content on the page, the main content is served by the PHP INCLUDES function. In addition, when a link is pressed, the main content changes to reflect the information pertaining to the link that was pressed.

The links on my site resemble this format: index.php?page=tournaments.php or http://www.mysite.com/index.php?page=tournaments.php

The main content area on my page uses the INCLUDES function with the following codes, it allows the main content "news.php" to be swapped with another page selected on the menu links.
<? if ( $page=='' ) { $page="news.php"; $l="?"; } else { $page="$page"; }?>
<?php include("$page"); ?>

Many people using INCLUDES use them to modify Headers/Footers while the rest of the page may have areas using INCLUDES depending on the page being viewed. My dilemma lies in the way the page is served information from a new page that is being loaded.

I would like to have a dynamic banner that is below the header, that also uses INCLUDES along with the main content of the site. Basically, I would like the Banner change depending on the link selected to match the content on that particular page. It didn't sound like a difficult problem at first because most people keep the entire content to be modified as a single file, but I would like to change multiple INCLUDES at the same time between different pages after selecting a link. The solution to my problem should serve content about the loading page (i.e. the banner & main content) from 2 sources, but being displayed at the same time based on the page selected from the menu.

Does anyone have any idea how I could make that work? Any help would be appreciated. Thank you.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
maxfaction is offline Offline
1 posts
since Oct 2004
Oct 18th, 2004
0

Re: Multiple PHP INCLUDES

It would be easier for you to use switch.
e.g.
[php]
switch($page) {
default:
$content = "news.php";
$title = "News page/Home page";
break;

case "links":
$content = "links.php";
$title = "Links page";
break;

case "tournaments":
$content = "tournaments.php";
$title = "Tournaments page";
break;
}
[/php]

etc etc.
those are just some examples where you can also add [php] <?=$title?> [/php] within your html <title> tags.
Now you can include the same as before in the page
[php]<?php include("$content"); ?> [/php]
Reputation Points: 12
Solved Threads: 5
Junior Poster
ReDuX is offline Offline
127 posts
since Sep 2004
Oct 18th, 2004
0

Re: Multiple PHP INCLUDES

Why bother enquoting $context in the include statement? Just slows down the parser...
Team Colleague
Reputation Points: 63
Solved Threads: 6
Supreme Evil Overlord
Roberdin is offline Offline
282 posts
since Feb 2003
Oct 18th, 2004
0

Re: Multiple PHP INCLUDES

handy for pages generated by those dreadfull wysiwyg things naming a file bob's-page.html
Reputation Points: 12
Solved Threads: 5
Junior Poster
ReDuX is offline Offline
127 posts
since Sep 2004
Oct 19th, 2004
0

Re: Multiple PHP INCLUDES

But why would that in anyway affect the variable? I mean, all you are doing by using "$context" is saying to PHP:

I'm typing some text here, feed this into the parser. If you find any variables, then evaluate them.

So essentially it's evaluating $context, and then sending the results off to the include() function, as apposed to just sending it off; if you see what I mean...
Team Colleague
Reputation Points: 63
Solved Threads: 6
Supreme Evil Overlord
Roberdin is offline Offline
282 posts
since Feb 2003
Oct 20th, 2004
0

Re: Multiple PHP INCLUDES

Well its a language construct rather than a function, And its more flexable using both ( and " ..
speed difference will be un-noticed on a small/non-busy site, unless he ends up getting 100k hits a month or more.
using them both will enable use of ssi and so on. where some servers dont like seeking ( using 'something' or just (something) ) and will get errors like "Stream does not support seeking" or similar.
Just tryin to be flexable is all :x
Reputation Points: 12
Solved Threads: 5
Junior Poster
ReDuX is offline Offline
127 posts
since Sep 2004
Oct 20th, 2004
0

Re: Multiple PHP INCLUDES

Ah, I wasn't aware of this...
Team Colleague
Reputation Points: 63
Solved Threads: 6
Supreme Evil Overlord
Roberdin is offline Offline
282 posts
since Feb 2003
Oct 20th, 2004
0

Re: Multiple PHP INCLUDES

Me either till a few weeks ago
Reputation Points: 12
Solved Threads: 5
Junior Poster
ReDuX is offline Offline
127 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Help with Querystring error
Next Thread in PHP Forum Timeline: Blank drop list





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC