gwood_25 Posted October 1, 2007 Share Posted October 1, 2007 Hi, I am new to php and am having a problem with a simple if statement. I am loading a float value from a database and if it is greater than zero, I would like to ouput the value. If not, display nothing. Here is my code but it doesn't work.... <? ...database code above works...when I add the following if statement...the code fails if ($row{'Price'} > 0) { echo $row{'Price'} } ?> Link to comment https://forums.phpfreaks.com/topic/71380-solved-simple-if-statement-not-working/ Share on other sites More sharing options...
jaymc Posted October 1, 2007 Share Posted October 1, 2007 if ($row{'Price'} > 0) { echo $row{'Price'}; } I think you may also have the syntax wrong Try this if ($row['Price'] > 0) { echo $row['Price']; } Link to comment https://forums.phpfreaks.com/topic/71380-solved-simple-if-statement-not-working/#findComment-359195 Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 brackets, not braces. $row['Price'] Link to comment https://forums.phpfreaks.com/topic/71380-solved-simple-if-statement-not-working/#findComment-359196 Share on other sites More sharing options...
d.shankar Posted October 1, 2007 Share Posted October 1, 2007 if ($row['Price'] > 0) { echo $row['Price']; // semicolon too } Link to comment https://forums.phpfreaks.com/topic/71380-solved-simple-if-statement-not-working/#findComment-359197 Share on other sites More sharing options...
gwood_25 Posted October 1, 2007 Author Share Posted October 1, 2007 Thank you so much. I changed to braces and still had a problem.... it was the semi colon. Thank you Link to comment https://forums.phpfreaks.com/topic/71380-solved-simple-if-statement-not-working/#findComment-359205 Share on other sites More sharing options...
gwood_25 Posted October 1, 2007 Author Share Posted October 1, 2007 sorry I meant to say I changed the braces to brackets and still had the issue.... when I added the semi colon... it worked. Thanks again for your help. Much appreciated Link to comment https://forums.phpfreaks.com/topic/71380-solved-simple-if-statement-not-working/#findComment-359206 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.