Forum Moderators: coopster

Message Too Old, No Replies

PHP Include Question

First Day with PHP

         

iJeep

7:02 am on Dec 11, 2002 (gmt 0)

10+ Year Member



I started to ask a question earlier and figured out the answer as I was typing it...SO I guess I will try that again...

I am rebuilding my ASP website to use PHP. I have been pretty successfull so far today (but haven't started any of the database conversion). The one problem I have and cannot understand is that it seems when I include a file that has an include command in it the php code on the second page doesn't get processed, it just dumps all the html onto the page...ex:

file1.php:
...
<?php include("file2.php");?>
...

file2.php:
...
<?php include("file3.php");?>
...

file3.php:
<?php if (something) {?>
this<br>
<?php } else {?>
that
<?php }?>

Then when I run file1.php the include from file3.php shows as:

this
that

not as one or the other. It works fine ran directly or with one include. Any way around this?

Nick_W

7:09 am on Dec 11, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's exactly what it should do. You're closing the php so it just runs any html outside of the php tags. Try this

file3.php:
<?
if(something) {
print("this<br>\n");
} else {
print("that");
}
?>

Nick
<?php }?>

iJeep

7:34 am on Dec 11, 2002 (gmt 0)

10+ Year Member



Hm...that didn't do the trick. Here is one of the codes exactly that is giving me a problem of showing both the if and then:

<?php if ( $showcat = 1 or!stristr($_SERVER['REQUEST_URI'], 'Daystar') or!stristr($_SERVER['REQUEST_URI'], 'Tech') ) {
echo('<a href="/?showcat=0"><img src="/images/sidecategories2.gif" border=0 alt="Browse Accesories"></a><br>');
} else {
echo('<a href="/?showcat=1"><img src="/images/sidecategories.gif" border=0 alt="Show Categories" width="200" height="45"></a><br>');
}?>

Works with one include, but not with two.

iJeep

8:08 am on Dec 11, 2002 (gmt 0)

10+ Year Member



I found the problem. It was actually a problem of me not getting enough sleep and typing .asp as the extension which brought up the old version of the page. I guess that is a new habbit that I will have to break. ;)

Thanks for the help Nick, that was the problem in one place.

Nick_W

8:10 am on Dec 11, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LOL! Glad it worked out ;)

Nick