Page 1 of 1
if statement problem
Posted: Tue Feb 03, 2004 11:47 am
by malcolmboston
was trying something out the other day, set a variable depending on a condition and then printing it elsewhere on the page, its used to tell someone if they have new mail or not
heres the code, its not my real code btw lol
Code: Select all
if
mysql_affected_row >= 1;
$mail_status= "You have New Mail!
else
$mail_status = "You Have No New Mail!
i havent tried to be syntaxicallyblah correct btw, just give you a brief idea
anyway basically, it wont set any variable, ive tried to do this on many projects and the outcome is the same
any ideas?
Posted: Tue Feb 03, 2004 11:52 am
by AVATAr
so....
Code: Select all
<?php
$iAffected = mysql_affected_rows();
if ($iAffected >=1){
$sMailStatus = 'You have mail';
} else {
$sMailStatus = 'You have no mail';
}
?>
Posted: Tue Feb 03, 2004 11:57 am
by malcolmboston
yeah basically, except that doesnt work
the code i have is....
Code: Select all
<?php
$newmail = mysql_affected_rows();
if ($newmail >=1)
{
$MailStatus = 'You have mail';
}
else
{
$MailStatus = 'You have no mail';
}
?>
however it wont print and when i check the var nothing comes up
Posted: Tue Feb 03, 2004 12:01 pm
by AVATAr
mysql_affected_rows(); returns something?
did you echo $MailStatus;
Posted: Tue Feb 03, 2004 12:03 pm
by malcolmboston
yeah, i made some dummy private messages, and it comes back with to, i thought the vars may not be able to be created in a conditional statement and then dismissed this as PHP is actually a good language and cannot be limited like that is it would cripple alot of functionality
also there is not way a variable cannot be created due to the way the statement is constructed
affected rows = 2 btw
Posted: Tue Feb 03, 2004 12:06 pm
by malcolmboston
yes i displays nothing
if i use the same code but like this
Code: Select all
<?php
$newmail = mysql_affected_rows();
if ($newmail >=1)
{
print= "You have mail";
}
else
{
print = "You have no mail";
}
?>
it works perfectly however i need to print it elsewhere on the page
Posted: Tue Feb 03, 2004 12:08 pm
by AVATAr
if you die($MailStatus); inmediately after the if statements... what happen?
Posted: Tue Feb 03, 2004 12:12 pm
by malcolmboston
i dont know im not on my webserver
but technically (im not even very good at condition statements) that code should be working right? even i can see that
Posted: Tue Feb 03, 2004 12:17 pm
by AVATAr
yep its ok
Posted: Tue Feb 03, 2004 12:58 pm
by Unipus
It looks to me like it might be a variable scoping problem. Is that code contained within a function, or being accessed with a function? It should definitely be setting to the default, so my only guess is that you're out of scope.
Without some die() statements, it's pretty hard to say what might be going on.