Jump to content

[SOLVED] IF Statement not catching?


virtuexru

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.