NULL values when field is formatted for currency

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
fbachofner
User
Posts: 70

NULL values when field is formatted for currency

Post by fbachofner »

I have some fields formatted to reflect they are currency-related fields.

Unfortunately, PHPMaker returns $0 when a field is NULL.

How do I make NOTHING display when a field is formatted as a currency but has no value.

[Imagine my users' concern when they look at the "Sold_Price" column and it reports $0 -- they will think something has been sold even when it is still in inventory!]


mobhar
User
Posts: 11746

Post by mobhar »

Simply write your code in "Row_Rendered" server event. For further information, please read "Server Events and Client Script" section in the help file.


danielc
User
Posts: 1601

Post by danielc »

Use this code in Row_Rendered server event:
if (($this->YourField->CurrentValue == "") || ($this->YourField->CurrentValue == 0))// check for null or 0
$this->YourField->ViewValue = "";


fbachofner
User
Posts: 70

Post by fbachofner »

Thanks danielc . . . works GREAT!

However, one PROBLEM example:

// Row Rendered event
function Row_Rendered() {
if (($this->STICKER($)->CurrentValue == "") || ($this->STICKER($)->CurrentValue == 0))
$this->STICKER_($)->ViewValue = "";
}

PHP seems to choke on the fact that this fieldname includes a "$"

I inherited DB with some poorly named field and can easily change those soon . . . but for a learning example am curious as to how one would deal with such a problem. Putting quotes around the fieldname does not help and throws a different error.

Ideas? Thanks in advance!

[Just to be clear, the above code for differently named fields (2 other such currency fields where I need to make sure NULLS do not display as "$0") works perfectly, so the code is valid except for this one particular use case.]


mobhar
User
Posts: 11746

Post by mobhar »

May we know the error message exactly you got?


fbachofner
User
Posts: 70

Post by fbachofner »

mobhar wrote:
May we know the error message exactly you got?

"Parse error: syntax error, unexpected ')', expecting variable (T_VARIABLE) or '$' in path-redacted\artworkinfo.php on line 1529"

"path-redacted" points correctly to the path of my app (when it is not redacted by me in this post! ;-) . . .


mobhar
User
Posts: 11746

Post by mobhar »

The error happened since the path name contains "(" or "$" character. Try to avoid using those characters from the field name.


danielc
User
Posts: 1601

Post by danielc »

The field name (STICKER_($)) will be convert to STICKER_xxx. You can search *info.php to find out the changed field name.

mobhar wrote:
Try to avoid using those characters from the field name.


fbachofner
User
Posts: 70

Post by fbachofner »

mobhar wrote:
The error happened since the path name contains "(" or
"$" character. Try to avoid using those characters from the field
name.

Thanks.

As I mentioned, I inherited the DB complete with some poor design choices.

I am now rectifying those problems! ;-)


fbachofner
User
Posts: 70

Post by fbachofner »

danielc wrote:
The field name (STICKER_($)) will be convert to STICKER_xxx. You can search *info.php
to find out the changed field name.

Thanks, that's a really good tip for future reference.

Of course in DBs I design I typically have "better" field names in the first place!


Post Reply