if statement problem

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
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

if statement problem

Post 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?
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

so....

Code: Select all

<?php
$iAffected = mysql_affected_rows();
if ($iAffected >=1){
   $sMailStatus = 'You have mail';
} else {
   $sMailStatus = 'You have no mail';
}
?>
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

yeah basically, except that doesnt work

the code i have is....

Code: Select all

&lt;?php 
$newmail = mysql_affected_rows(); 
if ($newmail &gt;=1)
{ 
   $MailStatus = 'You have mail'; 
} 
else 
{ 
   $MailStatus = 'You have no mail'; 
} 
?&gt;
however it wont print and when i check the var nothing comes up
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

mysql_affected_rows(); returns something?

did you echo $MailStatus;
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

if you die($MailStatus); inmediately after the if statements... what happen?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

yep its ok
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

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