Welcome to WebmasterWorld Guest from 54.196.212.62

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

hide value 0.00

     

helenp

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

WebmasterWorld Senior Member 10+ Year Member



Hi,
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

dreamcatcher

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

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Hi Helen,

You can use the substr function:

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

Hope that helps.

dc

jamesa

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

WebmasterWorld Senior Member 10+ Year Member



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"])

helenp

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

WebmasterWorld Senior Member 10+ Year Member



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"]);}
}

helenp

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

WebmasterWorld Senior Member 10+ Year Member



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

SeanW

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

10+ Year Member



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.

Sean

JamShady

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

10+ Year Member



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.

helenp

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

WebmasterWorld Senior Member 10+ Year Member



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.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month