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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.