homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

hide value 0.00

 9:35 am on Aug 28, 2005 (gmt 0)

I have some mysql columns that gives me amounts,
and it is very irritating that the value 0.00 comes up.

Using str_replace like this takes all the 0's away and leave 60 as 6...
$row["comision"] = str_replace("0.00", " ", $row["comision"]);

In this exampel the hundred values works perfect but in case thousands 1000.00 it leaves me with 100

if ($row["comision"] == 0.00)
if ($row["pagado"] == 0.00)
{$row["comision"] = str_replace("0.00", " ", $row["comision"]);}
{$row["pagado"] = str_replace("0.00", " ", $row["pagado"]);}

Any clues what to do to not show the amounts if it is 0.00?

Thanks in advance



 9:45 am on Aug 28, 2005 (gmt 0)

Hi Helen,

You can use the substr function:

if (substr($row["comision"],0,2)=='0.')
//don`t show

Hope that helps.



 9:49 am on Aug 28, 2005 (gmt 0)

If I understand your question right, here's two things you can try:

Single quotes to force str_replace to take '0.00' literally instead of it evaluating 0.00 as zero:
str_replace('0.00', " ", $row["comision"])

If that doesn't work, use a regexp:
preg_replace("/^0\.00$/", " ", $row["comision"])


 9:52 am on Aug 28, 2005 (gmt 0)

Thanks a billion,
been reading substr as well, didnīt understand :)

In the { } I used str_replace and works perfect.

if (substr($row["comision"],0,2)=='0.')
{$row["comision"] = str_replace("0.00", " ", $row["comision"]);}
if (substr($row["pagado"],0,2)=='0.')
{$row["pagado"] = str_replace("0.00", " ", $row["pagado"]);}


 10:33 am on Aug 28, 2005 (gmt 0)

Thanks Jamesa,
I am afraid you answered at the same time as dreamcatcher :)
Dreamcatchers exampel works, anyway I tried yours, the first take away 0`s it shouldnīt and the second gave errors.
Thank you anyway


 2:47 pm on Aug 28, 2005 (gmt 0)

Is this column of type float or (var)char? It would seem the appropriate comparison should be used instead of regexp.

<? if ($row['commission']!= 0) {?>Your commission is <? =$row['commission']?><? }?>

use the string literal "0.00" above if the column is a string.



 4:10 pm on Aug 28, 2005 (gmt 0)

Why don't you just use REPLACE() in your MySQL query to remove fields that are equal to 0.00? Surely that'd be a lot easier.


 6:41 pm on Aug 28, 2005 (gmt 0)

thanks to both,
The columns are decimal(10,2)

I was searching in mysql and didnīt find it,
anyway I had problems with the sums and substracting when there was no amount in one of the fields, so I think I need the value 0.00, so I prefered not to toch the select, but I suppose the replace would work as well.

Anyway it is done and works.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved