Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF statement problem...

Status
Not open for further replies.

dle46163

IS-IT--Management
Jul 9, 2004
81
US
Hi!

I'm trying to format an if statement for OsCommerce like this:

if ($products_price != "$0.00"){
echo $products_price;
}

For testing, I can just echo $products_price and it will show me $0.00. However, when I put the IF statement in, it acts as if $products_price never equals $0.00! I know in this instance it does equal $0.00 BUT it never acts that way! Is there maybe some sort of currency variable type that could be causing this? I just need to do a simple compare... Any feedback would be great!

-dle
 
Are you sure it's got the dollar sign in there? I recall that OSCommerce is very language- and currency-agnostic, so it seems unusual to me that the currency character would be included in the string.



Want the best answers? Ask the best questions! TANSTAAFL!
 
That's what seemed odd to me too... If I straight out echo $products_price it gives me $0.00!

 
Perhaps I'm missing something obvious, but I don't see the problem.

Your code above says, if $products_price does NOT equal $0.00 then print the price.... but if you just straight out print it it does equal $0.00

 
PHP supports neither the creation of new types nor the overloading of functions, so if echo says its there, I'll take its word for it.

It's been a while since I worked with OSCommerce, so forgive me if I seem like I'm grasping at straws.

If you issue the command:

echo '"' . $products_price . '"';

does it show any spaces at the beginning or end of the string?



Want the best answers? Ask the best questions! TANSTAAFL!
 
I had tested the space thing and there were no spaces...I even went as far as doing a str_replace on the dollar sign so I was simply left with the numbers and decimal. After all that I still couldn't get the IF statement working!!

Soooo, I tracked down the variable at the point it gets assigned values and turns out it's a huge string of junk including multiple variables and HTML code... Even though the echo statement was spitting out $0.00 the variable certainly was not just set to $0.00. Thus, I was able to find a different variable (within the $products_price assignment) which actually held the dollar amount I was looking to compare in my IF statement. I used that and sure enough it works! Pretty strange I guess...I've never done code that way but it appears to work just fine. Thanks for all your help!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top