Welcome to WebmasterWorld Guest from 54.167.46.29

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

hide value 0.00

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 27, 2003
posts:1308
votes: 0


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

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

Senior Member

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

joined:Mar 30, 2003
posts:3719
votes: 0


Hi Helen,

You can use the substr function:

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

Hope that helps.

dc

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 15, 2002
posts:710
votes: 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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 27, 2003
posts:1308
votes: 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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 27, 2003
posts:1308
votes: 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)

Preferred Member

10+ Year Member

joined:Dec 30, 2003
posts:428
votes: 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.

Sean

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

New User

10+ Year Member

joined:May 29, 2005
posts:37
votes: 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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 27, 2003
posts:1308
votes: 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.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members