virtuexru Posted January 5, 2009 Share Posted January 5, 2009 OK, I have a few rows in my database that are filled with the following string: $CALL So, I'm trying to do a if/else statement to replace that with just "CALL" but it seems as though the IF statement isn't catching it at all. Here is my code: <?php while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $o_price = $row['_price']; if($o_price == "$CALL") { //problem is that it's not catching this section, it skips directly to else, even when the row is actually "$CALL" $price = "CALL"; } else { $o_price = str_replace(",","",$o_price); $o_price = str_replace("$","",$o_price); $price = $o_price + $overflow; $price = "$".$price; } ?> Link to comment https://forums.phpfreaks.com/topic/139543-solved-if-statement-not-catching/ Share on other sites More sharing options...
rhodesa Posted January 5, 2009 Share Posted January 5, 2009 since $ designates a variable, and variables inside double quotes are evaluated, the following: if($o_price == "$CALL") won't do what you expect...use this: if($o_price == '$CALL') or if($o_price == "\$CALL") Link to comment https://forums.phpfreaks.com/topic/139543-solved-if-statement-not-catching/#findComment-729931 Share on other sites More sharing options...
GingerRobot Posted January 5, 2009 Share Posted January 5, 2009 So the row contains the literal text $CALL? If so, you need to demarcate the string with single quotes, not doubles. $CALL would be treated a variable and so would be evaluated inside those double quotes. Put it inside single quotes and it'll be treated as a literal. if($o_price == '$CALL') To further explain: $foo = 'bar'; echo $foo; //echos bar echo "$foo"; // echos bar echo '$foo'; //echos $foo Edit: Beaten to it but thought i'd post with those examples anyway. Link to comment https://forums.phpfreaks.com/topic/139543-solved-if-statement-not-catching/#findComment-729936 Share on other sites More sharing options...
virtuexru Posted January 5, 2009 Author Share Posted January 5, 2009 You guys are great. I feel like a retard. Thank you! Link to comment https://forums.phpfreaks.com/topic/139543-solved-if-statement-not-catching/#findComment-729952 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.