Jump to content

PHP linking/Include code.


xplicit503

Recommended Posts

I found your site while browsing through google and it seemed to be a great community. I looked up in this site what I had needed in the FAQ section of the "Newbie Help Forum", which was the include code/php linking. Now from what I have read in other threads people have been flamed for "retarded" questions such as the one I am asking, but I did just start to scrape the surface of the php world, and I am in need of assistance.

Current Code in use:
[code]<?php include 'news.php';
         switch($_GET['id']){
         case 'news':
         include 'news.php';
         break;
         case 'courses':
         include 'courses.php';
         break;
                 ?>
[/code]

The problem is that it works, but when I click on my links it still leaves the default included content in the table.
I've been searching for a few days now, and this was my last option. If you need to see the actual site please let me know. Thanks.
Link to comment
Share on other sites

Hi, welcome to this forum.

I'm not sure what you mean since you didn't post a whole lot of code. However, I can share a couple of things I noticed.

1) The news.php is included all the time at the top, and it will get included again if the id is "news". I don't think that's what you intended. You might want to remove the first one or use include_once() or require_once() on both statements.

2) You don't have an ending right curly brace that's needed to close off the switch statement.


hth.
Link to comment
Share on other sites

My appologizes for the lack of information, but I needed to change the directory protection off. To give the site url to actually view the problem in person. [a href=\"http://www.xplicit.chatvisual.com/bt/\" target=\"_blank\"]Link to website[/a]

1.) I have placed in the include_once() like so:
[code]
<?php include_once('news.php');
switch($_GET['id']){
case 'courses':
include 'courses.php';
break;
case 'events':
include 'events.php';
break;
case 'staff':
include 'staff.php';
break;
case 'tools':
include 'tools.php';
break;
case 'about':
include 'about.php';
break;
}?>[/code]
Well the right curly brace was missing in the first post for some reason. But it is in there now. Although the and "news" advice fixed somethings, along with the include_once() code. But now click on the courses button.(The only operational one so far on the link) You still see at the top of the content box the old content from the news.php
Link to comment
Share on other sites

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]You still see at the top of the content box the old content from the news.php[/quote]
Sorry, I don't see or understand what you mean because I don't know what news.php really contains. But if you're seeing it, well it's because news.php is being included every time! You got it at the top of the page.

You may already know this, but the links for the "About", "Tools", etc. are using "page=" instead of "id=". Your code shown is using "id" and not "page".

Read up on include/require include_once/require_once at php.net.
Link to comment
Share on other sites

Hmm, The news.php's content is text that says: "Coding CMS initiated. Site is still about 30% done." Appologies on me being extremly unclear, its just that I have been working on this for a few hours and my head hurting.
What could I do to make the news.php show up just on the index.php and no other page? Currently I went back to my original understanding of the include/linking code from the FAQ:
[code]
        <TD width="481" ROWSPAN=4 valign="top" class="content03">
        <div align="left">
         <?php include_once("news.php"); ?>
         <?php switch($_GET['id']){
         case 'courses':
         include 'courses.php';
         break;
         case 'events':
         include 'events.php';
         break;
         case 'staff':
         include 'staff.php';
         break;
         case 'tools':
         include 'tools.php';
         break;
         case 'about':
         include 'about.php';
         break;
         }?>
          </div>
        </TD>
      </TR>
      <TR>
[/code]
Im not certain on where to put in the switch code (thus reason why I am in the newbies forum.)
Link to comment
Share on other sites

Whatever way you determine it's the index page, use it to only display the news.php.

if (something) {
include_once("news.php");
}


That "something" condition, only you know.

Example:

if (FALSE !== strpos($_SERVER['PHP_SELF'], 'index.php')) {
include_once("news.php"); // We're on the index page
}
Link to comment
Share on other sites

Ah, after so long I finally got the script where I want it! I added in a the following line:
[code]
         <?php switch($_GET['id']){
         default: include_once('news.php');
         break;
[/code]
Instead of the include code it made more sense to make the default in the script itself include the news.php only once. Thanks toplay for your assistance and ability to hang in there with me while I struggled to explain php in the little way that I could. Also I did like the meathod you helped me out with, instead of just giving me the code it was step to step and made me think on my own.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.