Go Back   Web Hosting UK Forums | Linux Windows Dedicated Server and cPanel VPS Hosting Forum > Support > php issues.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-20-2008, 10:50 PM
new member
 
Join Date: Nov 2007
Posts: 6
Question links to load files

Hi
i want to make a a page (php) and in the menu to have links that call external files (either html, or php, or txt) which contain the main content. That content would like to be placed each time in the first page which is like a template.
so a typical address would be server.com/index.php?p=music

This is easily done but the thing that i can't do is when you click the links i don't want to have the complete page -template- loaded, i prefer to have only the text changed in the main area and everything else like top area with logo, banner and bottom area with emails numbers etc to stay as is.

is that something possible with php?
do i have to use frames? hope not.

please be easy on me, its my first post!
Reply With Quote
  #2 (permalink)  
Old 01-20-2008, 11:04 PM
Senior Member
 
Join Date: Dec 2006
Posts: 544
Send a message via MSN to karimali831
Default

I'll try and help but I don't really understand.

Are you trying to view the contents of the .php page only or index.php aswell as the other page?
Reply With Quote
  #3 (permalink)  
Old 01-21-2008, 12:00 AM
Senior Member
 
Join Date: Dec 2006
Posts: 544
Send a message via MSN to karimali831
Default

(Right, the contest starts exackly now and I think I'm the first person to help =D 12:00:00 21st of January and I damn hope the below post counts )


The only way I could think of this is to create a new page; e.g. index2.php
Use

Code:
<? 
$site = $_GET['site'] . ".php"; 

if(file_exists($site)) { 
    include($site); 
} else { 
  include('page.php');  
} 
if(($_GET['site'])) 
     ?></td>
Create the link, this won't include the main template from index.php
If I had to do that, I would do it that way.

Good luck
Reply With Quote
  #4 (permalink)  
Old 01-21-2008, 12:45 AM
new member
 
Join Date: Nov 2007
Posts: 6
Cool

I should have been clearer.

I have a template page index.php.
I also have text files (music.txt, events.txt, links.txt etc) that contain all the content - text.
In my index.php page I have the menu section. Each link calls each text file and the contents of the text file appear in the index.php.

the links look like this:
<?php echo htmlentities($_SERVER['PHP_SELF']);?>?p=events">Events</a>

when i click the links work fine but the template page is loading every time and i'd like not to. i just want the main area, where the contents of the text files appear, to reload and not the whole index.php


is that more understandable? i hope

thanx
Reply With Quote
  #5 (permalink)  
Old 01-21-2008, 09:07 AM
Member
 
Join Date: Nov 2007
Posts: 33
Default

Hi pepperoni,

I can offer this as a solution. It may not be suitable as it loads the whole page including all your 'bits'. However, by clicking the links only the selected section is displayed. It uses javascript (which I don't like) but is fairly simple to understand.

<HTML>
<HEAD>

<style type="text/css">
.head {
font-family: Arial;
position: absolute;
top: 1;
visibility: visible;
z-index: 2;
}
.text {
font-family: Arial;
position: absolute;
top: 170;
visibility: hidden;
z-index: 2;
}
</style>


<SCRIPT TYPE="text/javascript">

var pageLast = 0;

function fwd(pageNext)
{
document.getElementById(pageLast).style.visibility = "hidden";
document.getElementById(pageNext).style.visibility = "visible";
pageLast = pageNext;
}
</SCRIPT>
</head>

<body OnLoad="fwd(0)">
<DIV ID="head" CLASS="head">
<h1 align="center">Some Heading here</h1>
<h2 align="center">A bit more here</h2>
<p align="center"><b>Blah, blah, blah.</b></p>
</DIV>

<DIV ID="0" CLASS="text">
<P>NOTE: This is the first section of text. This is displayed when the page is first loaded. To get to the next section <U OnClick="fwd(1)">click here</U></P>
</DIV>

<DIV ID="1" CLASS="text">
<P>This is the second section. You can have mulitple choices like this. Where do you want to go now? -<BR><BR>
part 2) <U OnClick="fwd(2)">Section 2</U><BR>
section 3) <U OnClick="fwd(3)">Section 3</U><BR>
page 4) <U OnClick="fwd(4)">Section 4</U></P>
</DIV>

<DIV ID="2" CLASS="text">
<P>Etc, etc, etc. Where now?<BR><BR>
a) <U OnClick="fwd(0)"> Back to the start?</U><BR>
b) <U OnClick="fwd(1)">You should be able to work out the rest</U></P>
</DIV>


</BODY>
</HTML>
Reply With Quote
  #6 (permalink)  
Old 01-21-2008, 10:04 AM
new member
 
Join Date: Nov 2007
Posts: 5
Send a message via Skype™ to rwsinter
Default

Hi

Check out some AJAX howto's - this is where you can build one template page and load other pages into DIVs dynamically. The two languages that can do this are PHP and ASP. I use ASP, so can help on the mechanics, just not the PHP syntax.

I won't bother writing a HOWTO here as there are plenty already out there. Go check AJAX PHP on Google...

Chris
Reply With Quote
  #7 (permalink)  
Old 01-21-2008, 10:29 AM
new member
 
Join Date: Nov 2007
Posts: 6
Default

thanx scottie2212 and rwsinter for the messages

i don't want to use javascript for the time being... i'll give it a try with ajax and php and see how it goes. i hope i find something good.
Reply With Quote
  #8 (permalink)  
Old 01-21-2008, 03:16 PM
Senior Member
 
Join Date: Jan 2007
Posts: 939
Default

if you don't want to use frames then you need to create a rich internet application environment using something like Ajax, Flex,Openlaszlo, zend studio,etc.
Most popular language for this sort of project is javascript, and populating div tags dynamically 'on the fly'

Zend studio uses php and javascript as its main languages.

Ajax with the Spry framework also can create what you need, and I would suggest probably the easiest of all to learn as the javascript is already written for you.
__________________
West Dorset Community
Reply With Quote
  #9 (permalink)  
Old 01-21-2008, 09:28 PM
new member
 
Join Date: Nov 2007
Posts: 6
Default

just to let you know i found those two pages and everything works great.
its exactly what i was thinking to do. quite happy!!

hxxp://homepage.mac.com/kevinmarks/staticjah.html

hxxp://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

thought i have doubts if that's the best solution... cause it wont work if people disable javascript. maybe there is something around with html+css which work in every browser. i'll keep ajax for now.


cheers
Reply With Quote
  #10 (permalink)  
Old 01-21-2008, 11:09 PM
Senior Member
 
Join Date: Jan 2007
Posts: 939
Default

It used to be a couple years ago that some people did disable jscript as a matter of course, but that is not true in this day and age. Jscript is the most popular language and most RIA (which is the way web development is heading) depend on it, so i wouldn't be too concerned about it imho.
__________________
West Dorset Community
Reply With Quote
  #11 (permalink)  
Old 01-22-2008, 10:47 AM
new member
 
Join Date: Nov 2007
Posts: 6
Default

you are right i think jon123
i'm not that concerned now using ajax or javascript... its not bad actually.
plus i didn't find any way around to make it using html+css

i found some good sites around about dynamic design.

cheers!
Reply With Quote
  #12 (permalink)  
Old 05-25-2008, 03:05 PM
j03 j03 is offline
Junior Member
 
Join Date: Feb 2007
Posts: 25
Default

OK, So you have a template, you want to include other flat files in it?

So you would want:
index.php with the design
home.txt, info.txt etc as the content?

Just clearing some things up here
Reply With Quote
  #13 (permalink)  
Old 05-25-2008, 04:12 PM
black-dog's Avatar
Member
 
Join Date: May 2008
Location: Newcastle under Lyme
Posts: 54
Send a message via Yahoo to black-dog
Default

Quote:
Originally Posted by pepperoni View Post
Hi
i want to make a a page (php) and in the menu to have links that call external files (either html, or php, or txt) which contain the main content. That content would like to be placed each time in the first page which is like a template.
so a typical address would be server.com/index.php?p=music
You need to be a bit careful about the way you do this. It would be very BAD to have something like

include($_GET['p']."php");

You must make sure that the URL will only access content that YOU want accessed.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:19 AM.
Copyright 2002-2007 WebHosting.uk.com. All rights reserved.
Web Hosting UK Forum