Problem to linking a different file in the same page

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
ileyla
Forum Newbie
Posts: 3
Joined: Fri Mar 04, 2005 2:25 am
Location: Malaysia
Contact:

Problem to linking a different file in the same page

Post by ileyla »

hi everybody

wanna ask u guys out there, now i have a problems to linking a different file within the same page. basically i have set the index page which display and comprise of three different file(right.php, left.php & main.php), using include function in php. the problem now is that,the left.php file contains a menu which will link to other page. What i want to know now is that, instead of linking the page to other new page, how can i link the menu and display the target file into where main.php located, without left.php and right.php location be changed :?

Hope u guys out there can helps me. Thanks al lot :D


feyd | bolding your entire post helps no one
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

how about creating a new php document, including the include files you want to appear on the page
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

this is usually done through setting a url variable which will tell the main content script to change content..
ileyla
Forum Newbie
Posts: 3
Joined: Fri Mar 04, 2005 2:25 am
Location: Malaysia
Contact:

Post by ileyla »

what do you means by setting the url variable.Basically i have used the
<a href=?main="includes/page1.php" method..But it seems doesn't work at all.can u show me any guidelines or any method that i did not include in this code. :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

example ONLY

Code: Select all

<?php

$includePath = '/your/includes/path/';
$page = (isset($_GET['p']) ? $_GET['p'] : '');
$knownPages = array('contact'=>'contact', 'products'=>'productsheet', 'default'=>'default');

if(array_key_exists($page, $knownPages))
{
  $knownPage = $knownPages[$page];
}
else
{
  $knownPage = $knownPages['default'];
}

include($includePath . $knownPage . '.php');
pages are called in this manor: main.php?p=contact
Last edited by feyd on Tue Mar 08, 2005 11:42 pm, edited 1 time in total.
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Post by Phoenixheart »

I think it might be easier using frames?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Frames are dead.... avoid them where they are not necessarry at all costs. They cause all kinds of problems, especially with search engines.

I use a switch() condition to change the content based upon the url variable. Kinda like feyd said.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

why are frames dead?
what problems do they cause with search engines?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Uh oh... I can see I have started something here......

Well ok they aren't dead but developers previously used them for structuring pages, to get menus in one frame, a header in another etc....

I may have exaggerated just a bit in my last post :lol:

Search engines see these individual frames as separate pages and when viewed, these pages do not appear the way they should do. There are ways around it using JavaScript trickery to redirect if the page isn't being viewed in the frameset - but then that's JS dependant.

In general I find that if it's just for the sake of having a nice layout in easy to manage individual files, I'd prefer to use includes in PHP along with the relevant switch conditions to change what is called in the includes depending upon values in $_GET.

Of course, frames do have their uses still. It's just that it is not always ideal to use them, and I try to avoid them as much as possible.

This is just my personal opinion though 8)
ileyla
Forum Newbie
Posts: 3
Joined: Fri Mar 04, 2005 2:25 am
Location: Malaysia
Contact:

Post by ileyla »

oo ok..thanks for all the guidelines thanks feyd!!..btw i'm still working on that problems..
Lots of thanks everybody :D
Post Reply