Page 1 of 1
NULL values when field is formatted for currency
Posted: Sat Aug 10, 2013 11:33 am
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!]
Re: NULL values when field is formatted for currency
Posted: Sat Aug 10, 2013 12:01 pm
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.
Re: NULL values when field is formatted for currency
Posted: Sat Aug 10, 2013 12:57 pm
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 = "";
Re: NULL values when field is formatted for currency
Posted: Sat Aug 10, 2013 6:32 pm
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.]
Re: NULL values when field is formatted for currency
Posted: Sun Aug 11, 2013 6:21 pm
by mobhar
May we know the error message exactly you got?
Re: NULL values when field is formatted for currency
Posted: Mon Aug 12, 2013 2:20 am
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! ;-) . . .
Re: NULL values when field is formatted for currency
Posted: Mon Aug 12, 2013 8:59 am
by mobhar
The error happened since the path name contains "(" or "$" character. Try to avoid using those characters from the field name.
Re: NULL values when field is formatted for currency
Posted: Mon Aug 12, 2013 11:07 am
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.
Re: NULL values when field is formatted for currency
Posted: Wed Aug 14, 2013 1:01 am
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! ;-)
Re: NULL values when field is formatted for currency
Posted: Wed Aug 14, 2013 1:32 am
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!