Forum Moderators: coopster

Message Too Old, No Replies

PHP Template

PHP Template

         

Afterlithe

7:37 pm on Mar 15, 2007 (gmt 0)

10+ Year Member



Hello again,
I have a small problem with one of my templates that you guys should be able to help me with.

I have a template that has php includes (header.php, footer.php, menu.php, and content.php) Organizing those includes on the page is a series of tables.

So far, it will only display the data called in cantent.php, because its calling that page. I want it to display the content page depending on what menu item is selected, in one of the table cells(where it currently displays content.php).

Like <a href="" target="content.php"></a> or something similar.

Hope it makes sense.

Here is the code:

<html>
<head>
<title> Test PHP Template </title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>

<body>
<?php
include ("head.php");
?>
<!-- Table for Main Body -->
<table>
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td valign="top" align="left" width="90">
<?php
include ("menu.php");
?>
</td>
<td width="1" bgcolor="lightskyblue" valign="top"> </td>
<td valign="top">

<?php
include ("content.php");
?>
</td>
<td width="1" bgcolor="lightskyblue" valign="top"> </td>
</tr>
</table>

</body>
</html>

[edited by: Afterlithe at 7:51 pm (utc) on Mar. 15, 2007]

lordbeezdje

9:23 pm on Mar 15, 2007 (gmt 0)

10+ Year Member



you could use $_GET variables

insert this BEFORE the script generates ANY output!

<?php
if(isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
header("Location:?page=firstpage");
}
?>

make your links like this

<a href='?page=newpage'>newpage</a>

where you include the content use

include($page.".php");

if you use subdirectories for you pages :

change header to
header("Location:?dir=firstdir&page=firstpage");

link to
<a href='?dir=newdir&page=newpage'>newpage</a>

and include to
include($dir."/".$page.".php");

this will work if you're not using frames

Afterlithe

9:58 pm on Mar 15, 2007 (gmt 0)

10+ Year Member



The links are working. But on the index page, I get this error:

Warning: Cannot modify header information - headers already sent by (output started at /home/........) on line 19

which is this portion of code from above:
{
header("Location:?page=firstpage");
}

No other file that is being included has header information in it.

And this error on the content cell:
Warning: main(.php): failed to open stream: No such file or directory

This only happens on the index.php page, when you click on a link it displays the way its supposed to.

lordbeezdje

10:10 pm on Mar 15, 2007 (gmt 0)

10+ Year Member



about the header error:

you might want to move the first php section (with the header part) to the top of the document. I.e. before your <html> opening tag
this would put the header call on line 8 in stead of 19

the error on the content call is because the url still doesn't contain the?page= part

if the header error still remains after this, you could use

if(!isset($_GET['page']))
{
$pageset = "false";
}
else
{
$page = $_GET['page'];
}

and the in the <head> of your script insert

<script langauge='javascript'>
<!--
str = '<? echo $pageset;?>';
if(str == 'false')
{
window.location = '?page=firstpage';
}
// -->
</script>

[edited by: lordbeezdje at 10:27 pm (utc) on Mar. 15, 2007]

Afterlithe

10:25 pm on Mar 15, 2007 (gmt 0)

10+ Year Member



Thanks for the quick reply. It worked, and I am kicking myself for not thinking of it sooner. My mind is all over the place today. Thanks for the help.

lordbeezdje

10:28 pm on Mar 15, 2007 (gmt 0)

10+ Year Member



you're welcome

Afterlithe

7:48 pm on Mar 16, 2007 (gmt 0)

10+ Year Member



Ok, running into this problem with the links.

I have a database page that displays all the records by 'id' on the page. Then links to the detailed page with more information. The list page displays everything fine and the link works, but how do I get the link to the detail page to display the correct 'id' from the db. Right now the detail page only displays the blank table where the content should be.

<a href="?page=press-release-archive-archive"><?php echo $row_list['title'];?></a>

There is the link that is on the list page, that directs the user to more information on the detail page depending on the 'id'

[edited by: Afterlithe at 7:52 pm (utc) on Mar. 16, 2007]

lordbeezdje

1:16 pm on Mar 17, 2007 (gmt 0)

10+ Year Member



if i understand this correctly, you want the content to be filled in with press-release-archive-archive.php and you want this page to show the correct press release according to which link a person clicked on.

in that case you can again use the $_GET variable.

make you script echo a link like <a href='?page=press-release-archive-archive&releaseid=12'><?php echo $row_list['title'];?></a>

and in the press-release-archive-archive.php use $_GET['releaseid'] to get the right id for the press release

I hope this solves your problem, but if i misunderstood please correct me

Afterlithe

7:51 pm on Mar 19, 2007 (gmt 0)

10+ Year Member



Thanks for the response, think I understand what you mean.

Link looks like this:

<a href="../press-release-archive-detail.php?id=<?php echo $row_list['id'];?>"><?php echo $row_list['title'];?></a>

And when you click on it, it displays the selected id with info on a custom detal page.

[edited by: Afterlithe at 8:12 pm (utc) on Mar. 19, 2007]