PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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….
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
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
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
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.