IF not working as expected HELP

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply

Fri Mar 21, 2003 5:25 am

I have spent hours trying to get this to work - I have had enough - though new to PHP I am not new to programming so this is just so frustrating:

Background : I am reading a MySQL data base and as normal testing a returned value for purposes of execution - no surprises so far.

When executing the IF statement ALWAYS returns FALSE and gives the wrong answer - HELP

Basic Function ===>>

function results_table_row($text1, $bool1, $text2, $bool2)
print "<tr>\n";

print "<td width=50% align=right>\n";
print "$text1 \n";
if ($bool1 = `1`)
{print "<img border=0 src=../images/Green%20Tick.bmp>\n";}
{print "<img border=0 src=../images/Red%20X.bmp>\n";}
print "</td>\n";

print "<td width=50%>\n";
if ($bool2 = `1`)
{print "<img border=0 src=../images/Green%20Tick.bmp>\n";}
elseif ($bool2 = `0`)
{print "<img border=0 src=../images/Red%20X.bmp>\n";}
{print "\n";}
print "$text2\n";
print "</td>\n";

print "</tr>\n";

Calling Mechanism =======>>>

print "<table border=0 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=100% id=AutoNumber1>\n";

//some debug code

print "Start\n";
print "type ";
print gettype($selected_detail->A_Family_Friendly_Logis);
print gettype($selected_detail->A_Nature_Silence_Logis);
print "$selected_detail->A_Family_Friendly_Logis\n";
print "$selected_detail->A_Nature_Silence_Logis\n";
print "Middle\n";
print $selected_detail->A_Family_Friendly_Logis;
print $selected_detail->A_Nature_Silence_Logis;
print "End\n";

results_table_row("A Family Friendly Logis",$selected_detail->A_Family_Friendly_Logis,"A Nature (Silent) Logis",$selected_detail->A_Nature_Silence_Logis);
results_table_row("A Vineyard Logis",$selected_detail->A_Vineyard_Logis,"A Cycling Logis",$selected_detail->A_Cycling_Logis);
results_table_row("A Hiking Logis",$selected_detail->A_Hiking_Logis,"A Fishing Logis",$selected_detail->A_Fishing_Logis);
results_table_row("A Snow Logis",$selected_detail->A_Snow_Logis,"",9);

print "</table>\n";

The various MySQL fields (ie $selected_detail->A_Family_Friendly_Logis) are all defined as TinyInt.


The code always prints the last section of the IF else pair/triplette for example first always puts red X - second always puts "" and not according to the appropriate value of ($bool1 or $bool2)

What, can someone help me, is wrong - i have tried `, " and ' and numerics

Many thanks in advance
Kindest regards
Sean McPoland

New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

Fri Mar 21, 2003 5:50 am

= is an assignment operator
== is a test operator
=== is a typecast test operator

if($bool1 = 1) actually assigns 1 to $bool1

if($bool1 == 1) would be true if $bool1 was 1,'1',"1"

if($bool1 === 1) would be true if $bool1 was 1 and only 1
avatar image based upon nasas apod (only updates if I post though)

Post Reply