User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,937 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,785 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 4468 | Replies: 7
Reply
Join Date: Oct 2004
Location: U.S. Virgin Islands
Posts: 1
Reputation: maxfaction is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
maxfaction maxfaction is offline Offline
Newbie Poster

Help Multiple PHP INCLUDES

  #1  
Oct 12th, 2004
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Location: in the j00-kay
Posts: 114
Reputation: ReDuX is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
ReDuX's Avatar
ReDuX ReDuX is offline Offline
Junior Poster

Re: Multiple PHP INCLUDES

  #2  
Oct 17th, 2004
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]
Reply With Quote  
Join Date: Feb 2003
Location: London, England
Posts: 281
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Rep Power: 7
Solved Threads: 6
Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: Multiple PHP INCLUDES

  #3  
Oct 18th, 2004
Why bother enquoting $context in the include statement? Just slows down the parser...
Reply With Quote  
Join Date: Sep 2004
Location: in the j00-kay
Posts: 114
Reputation: ReDuX is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
ReDuX's Avatar
ReDuX ReDuX is offline Offline
Junior Poster

Re: Multiple PHP INCLUDES

  #4  
Oct 18th, 2004
handy for pages generated by those dreadfull wysiwyg things naming a file bob's-page.html
I'm pink, therefore, im spam.
http://www.vivaci.net - Quality Webhosting
http://gaming.vivaci.net - FAST UK Gaming servers
http://www.getsigned.org - Free Image Uploads
Reply With Quote  
Join Date: Feb 2003
Location: London, England
Posts: 281
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Rep Power: 7
Solved Threads: 6
Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: Multiple PHP INCLUDES

  #5  
Oct 19th, 2004
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...
Reply With Quote  
Join Date: Sep 2004
Location: in the j00-kay
Posts: 114
Reputation: ReDuX is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
ReDuX's Avatar
ReDuX ReDuX is offline Offline
Junior Poster

Re: Multiple PHP INCLUDES

  #6  
Oct 20th, 2004
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
I'm pink, therefore, im spam.
http://www.vivaci.net - Quality Webhosting
http://gaming.vivaci.net - FAST UK Gaming servers
http://www.getsigned.org - Free Image Uploads
Reply With Quote  
Join Date: Feb 2003
Location: London, England
Posts: 281
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Rep Power: 7
Solved Threads: 6
Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: Multiple PHP INCLUDES

  #7  
Oct 20th, 2004
Ah, I wasn't aware of this...
Reply With Quote  
Join Date: Sep 2004
Location: in the j00-kay
Posts: 114
Reputation: ReDuX is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
ReDuX's Avatar
ReDuX ReDuX is offline Offline
Junior Poster

Re: Multiple PHP INCLUDES

  #8  
Oct 20th, 2004
Me either till a few weeks ago
I'm pink, therefore, im spam.
http://www.vivaci.net - Quality Webhosting
http://gaming.vivaci.net - FAST UK Gaming servers
http://www.getsigned.org - Free Image Uploads
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 8:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC