Page 1 of 1

working outside an 'include'

Posted: Fri Jan 26, 2007 3:34 pm
by Addos
I wonder if anybody can help me work out the following. I have a single page in a small shopping cart and there are 2 categories of items for sale CD’s and books’. I want to run an ‘if statement’ looking for the categories and if it’s ‘1’ then I want the <h1> heading to read “CD’s for sale” and if its 2 I want it to read “books for sale”. Now my problem is that when I run the script below everything returns the correct result….

Code: Select all

<h1>???? for sale </h1>
 <hr width="680" size="1" noshade>
  <p><?php echo($cart->cartLinks());?></p>
<?php include("2/IncResults.php");?>
 <?PHP if ($urlcategory = = 1) echo 'heading h1';?>
<?PHP if ($urlcategory = = 2) echo 'heading h2';?>
However what I really need to run in order to make the page display/format in the browser correctly is

Code: Select all

<h1> <?PHP if ($urlcategory = = 1) echo 'heading h1';?>
<?PHP if ($urlcategory = = 2) echo 'heading h2';?></h1>
 <hr width="680" size="1" noshade>

  <p><?php echo($cart->cartLinks());?></p>
<?php include("2/IncResults.php");?>
But because the <?PHP if ($urlcategory = = 1) echo 'heading h1';?> etc is above the include statement it’s throwing the Undefined variable error, so can anyone give me a few ideas how this is normally resolved?
Many thanks

Posted: Fri Jan 26, 2007 4:12 pm
by matthijs
change the = = to == or === ?

Posted: Fri Jan 26, 2007 7:16 pm
by Addos
Hi,
Thanks for the reply but the code works fine its just that I can't get it to work outside (above) <?php include("cw2/CWIncResults.php");?> and wonder how to go about sorting this.
Thanks

Posted: Fri Jan 26, 2007 8:00 pm
by nickvd
($urlcategory = = 2)

WILL NOT WORK CORRECTLY...

($urlcategory == 2)

WILL WORK AS YOU EXPECT...


Sorry for yelling, but I wanted to make sure you understood us..

Posted: Sat Jan 27, 2007 5:13 am
by Addos
Thanks for this and I appreciate that = = should be == however as I typed this up in Word this is where the = = came from and in the code on my .php page it’s == so really I still have the same problem. I understand that there should not be the gap but as I say this is only cos I edited my question in a Word doc before I posted it. So I’m still stuck with the problem of trying to get this original question sorted.
Thanks again
B

Re: working outside an 'include'

Posted: Sat Jan 27, 2007 5:44 am
by volka
Addos wrote:But because the <?PHP if ($urlcategory = = 1) echo 'heading h1';?> etc is above the include statement it’s throwing the Undefined variable error
If $urlcategory is defined in 2/IncResults.php you can use it only after the file is included.