PDA

View Full Version : can it be done?


sjc_unique
08-22-2002, 08:00 PM
right, I am hoping someone can tell me how to do the following. i am guessing i can do it involving the switch() function, but before i try, want to seek your advice. Here's what i am looking to do:

when a link is clicked, text appears in a particular place on that page. So, rather than load a completely new page for a few paragraphs of info, it include()s, for example info.html.

So i assign a <td> for this function, and when a link is clicked, info.html appears in that <td>. And depending what link depends what file it include()s.

Is it possible? i know i can use frames in html, but i would prefer to use something like this. i hate frames.


Thanks


SJC

stuntboy
08-22-2002, 08:26 PM
Yes you can use the include() function http://www.php.net/manual/en/function.include.php

what do your links look like? if you have something like
http://blah.com/page.php?inclu=bob

you can have the function like this
<?php
include("$inclu.php")
?>

that will load bob.php

hope that makes sence

sjc_unique
08-22-2002, 08:45 PM
i know how to use the include() function. but i want to combine it with a link. so that when a link is clicked a different .html or .php file is loaded into a <td>.

stuntboy
08-22-2002, 09:10 PM
That is what I was getting at though poorly.

you are going to need it to be one file you are loading it from lets say the page is main.php

Now you have the link to it as
<a href="main.php?aVar=thepage">A link</a>

when you click that link it will load main.php with aVar available as if it was submitted from a form with the get method. I like to make the variables value the same as the name of the file you want to load. that makes it so that you can simply use the include function and no switch or if statements needed

include($_GET['aVar'].'.html') is all that is needed.

sjc_unique
08-22-2002, 09:30 PM
ok, right. I kinda have it working.

If i hit the link, news1.html appears in the right place. which is pefect.

However, when going into the page (and the link has not been clicked yet)....i get this:

Warning: Failed opening '.html' for inclusion (include_path='.:/php/includes:/usr/share/php') in /home/virtual/site15/fst/var/www/html/index2.php on line 132


so it is trying to include the file in the page before it should be. can i stop this!??!?!?!?

Thanks

SJC

stuntboy
08-22-2002, 09:59 PM
do you have a default page?

if so:

<?php
if(!isset($_GET['aVar']))$page="default";
else $page=$_GET['aVar'];
include("$page.html");
?>

that should make it work

sjc_unique
08-22-2002, 10:10 PM
thanks mate. owe you a favour if u need one.

my site is looking the nads!!!

SJC

livefire
09-19-2002, 12:46 AM
that script work good for me too, its the only one thats worked for me. but is there a way to add a 404 page if it can't find the page it was looking for?

stuntboy
09-19-2002, 01:02 AM
How about:

<?php
if(!isset($_GET['aVar']))$page="default";
else $page=$_GET['aVar'];
if(!file_exists("$page.html"))$page="404page";
include("$page.html");
?>

Spookster
09-19-2002, 01:48 AM
Originally posted by livefire
that script work good for me too, its the only one thats worked for me. but is there a way to add a 404 page if it can't find the page it was looking for?

That's what a .htaccess file is for:

http://www.javascriptkit.com/howto/htaccess2.shtml