IF Statement problems

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!

Moderator: General Moderators

Post Reply
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

IF Statement problems

Post 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
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Re: IF Statement problems

Post 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.
Last edited by scorphus on Sun Jan 11, 2004 6:12 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

OMG I have the variable set to $jantable instead of $janrows

:(:( ty for your swift response
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

thats not why

its because you're using one = instead of two (==) like scorphus said..
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
Post Reply