Closed Thread Icon

Preserved Topic: PHP driven template help. Pages that link to <a href="https://ozoneasylum.com/backlink?for=20899" title="Pages that link to Preserved Topic: PHP driven template help." rel="nofollow" >Preserved Topic: PHP driven template help.\

 
Author Thread
Skatefx
Bipolar (III) Inmate

From: Small Patch of Grass in CT
Insane since: Mar 2001

posted posted 05-08-2001 20:11

Well i am having yet another problem with php. what im trying to do is make a template. i am going to have 3 columns and in each column ill use the include function to include a seperate html file. this is all good until it come to changing the center html file to another file. for instance i want to use a link in the first html file in order to change the html file in the 3nd column. Basically if you dont get what im saying. here is my attempt at it.
the code for the php script is as follows

code:
<?

$leftside="leftside.html";

$middle="middle.html";

$rightside="rightside.html";

if ($link == articles){
$middle="articles.html";
}
?>

<html>
<head>
<title>test</title>
</head>

<body>

<table width="100%">
<tr>
<td width="15%">
<? include($leftside); ?>
</td>
<td width="60%">
<? include($middle) or die("cant open articles"); ?>
</td>
<td>
<? include($rightside); ?>
</td>

</tr>

</table>

</body>

</html>


does anybody have any clue whats wrong?

thanks alot
mike

"Society, we all know that somethings wrong. And we've know it all along" -Pennywise-

linear
Paranoid (IV) Inmate

From: other places
Insane since: Mar 2001

posted posted 05-08-2001 20:25

looks to me like the code works fine, but you have a path expansion issue:

try changing
$middle="articles.html";
to
$middle="/home/skatefx/public_html/php/layouttest/articles.html";

see how that goes.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-09-2001 01:03

hokay.

First where is $link set? I think what you are trying to do is pass that variable along in the query string. something like
http://whatever.com/ index.php3?link=articles

Is that right?
In that case you need to initialize the variable somewhere so that things don't break.

In the top you could put something like

if (!isset($link)) {
$link = "default";
}

That way if it is not set you don't break stuff when looking for it.

Also in your comparison you need to put articles in quotes. Otherwise it's looked at as a constant.

if($link == "articles") { ....

I did a this and quick tried it here and the only error I get now is opening the files (because of course I don't have them)


Walking the Earth like Kane

Skatefx
Bipolar (III) Inmate

From: Small Patch of Grass in CT
Insane since: Mar 2001

posted posted 05-09-2001 19:20

hey bitdamaged would you be able to explain that a little more in depth for me? im kinda a php newbie.

thanks

"Society, we all know that somethings wrong. And we've know it all along" -Pennywise-

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-09-2001 19:41

Umm, which part?

The line that seems to be breaking is the if statement.
There are two main problems here. First you are using the variable $link. Where is that variable getting set?

In this script that variable is not getting set anywhere and as such is going to break the script.

Second you are comparing $link == articles. The word "articles" needs to be in quotes otherwise PHP will break.

All that stuff in the beginning of my post is in regards to how most people make "templates" work with PHP. usually you pass some sort of identifier in the QUery String. (your query string is everything after the "?" in a URL and is not PHP specific) So a lot of times you'll see something like this.
http://mysite.com/news.php?sid=12000

Then In news.php you will now automatically have access to a variable called $sid. You can then do stuff based on this ID number (which will usually be the Primary Key of a story in your database) .

The thing is that your PHP script by default will not know that sid is supposed to exist. So by using an isset($sid) statement you can see if $sid has been set in the query string and have your script react accordingly.

In your case I assumed (and maybe mistakenly) that your were going to pass the link variable along to the page

Umm am I making sense?


Walking the Earth like Kane

« BackwardsOnwards »

Show Forum Drop Down Menu