Page 1 of 1

IF Statement problems

Posted: Sun Jan 11, 2004 6:05 pm
by John Cartwright
Okay I have $jantable= ("3"); set in a different file for futur reference.

This is what I have right now

Code: Select all

<?php

if ($jantable = "3") &#123;
	echo "<table width="688" border="1" cellpadding="0" cellspacing="0" bordercolor="0" bgcolor="E2E2E2">\n"
        ."<tr bordercolor="E2E2E2">\n"
    	."<td width="82"><div align="center"><font size="2" face="Arial, Helvetica, sans-serif">$jan1d</font></div></td>\n"
    	."<td width="600"><font size="2" face="Arial, Helvetica, sans-serif">$jan1</font></td>\n"
  	."</tr>\n"
  		."<tr bordercolor="E2E2E2">\n"
    	."<td>&nbsp;</td>\n"
        ."<td>&nbsp;</td>\n"
  	."</tr>\n"
  	."<tr bordercolor="E2E2E2">\n"
    	."<td width="82"> <div align="center"><font size="2" face="Arial, Helvetica, sans-serif">$jan2d</font></div></td>\n"
    	."<td width="600"><font size="2" face="Arial, Helvetica, sans-serif">$jan2</font></td>\n"
  	."</tr>\n"
  	."<tr bordercolor="E2E2E2">\n" 
    	."<td>&nbsp;</td>\n"
    	."<td>&nbsp;</td>\n"
  	."</tr>\n"
  	."<tr bordercolor="E2E2E2">\n" 
    	."<td width="82"> <div align="center"><font size="2" face="Arial, Helvetica, sans-serif">$jan3d</font></div></td>\n"
    	."<td width="600"><font size="2" face="Arial, Helvetica, sans-serif">$jan3</font></td>\n"
  	."</tr>\n"
	."</table>\n";
&#125;
if ($jantable = "2" ) &#123;
	echo "<table width="688" border="1" cellpadding="0" cellspacing="0" bordercolor="0" bgcolor="E2E2E2">\n"
        ."<tr bordercolor="E2E2E2">\n"
    	."<td width="82"><div align="center"><font size="2" face="Arial, Helvetica, sans-serif">$jan1d</font></div></td>\n"
    	."<td width="600"><font size="2" face="Arial, Helvetica, sans-serif">$jan1</font></td>\n"
  	."</tr>\n"
  		."<tr bordercolor="E2E2E2">\n"
    	."<td>&nbsp;</td>\n"
        ."<td>&nbsp;</td>\n"
  	."</tr>\n"
  	."<tr bordercolor="E2E2E2">\n"
    	."<td width="82"> <div align="center"><font size="2" face="Arial, Helvetica, sans-serif">$jan2d</font></div></td>\n"
    	."<td width="600"><font size="2" face="Arial, Helvetica, sans-serif">$jan2</font></td>\n"
  	."</tr>\n"
	."</table>\n";
&#125; 
?>
When I run the code in my website both tables are showing up. I've tried 100 different things but I cannot seem to get it working. Any help is appreciated. TY :D

Re: IF Statement problems

Posted: Sun Jan 11, 2004 6:08 pm
by scorphus

Code: Select all

<?php
if ($jantable = "3") {
?>
Here you are not checking for equality between $jantable and "3". The condition to be tested on the if statement is a definition and almost all definitions return true.

Just change the attribution (=) operator to the logical equals operator (==) and this should work.

Code: Select all

<?php
if ($jantable == "3") {
/*...
...*/
if ($jantable == "2") {
?>
Regards,
Scorphus.

Posted: Sun Jan 11, 2004 6:11 pm
by John Cartwright
OMG I have the variable set to $jantable instead of $janrows

:(:( ty for your swift response

Posted: Sun Jan 11, 2004 6:56 pm
by d3ad1ysp0rk
thats not why

its because you're using one = instead of two (==) like scorphus said..

Posted: Tue Jan 13, 2004 8:23 pm
by John Cartwright
Oh no I had that set before I just took it off for some reason simply trying different things. Ty for help guys