Gossamer Forum
Home : Products : DBMan : Customization :

conditional display of field

Quote Reply
conditional display of field
I'm trying to set up a conditional display of a field, IF it has data in it.
I tried this code (based on a posting I found here), but it doesn't work -- the field displays regardless of whether it has data in it or not:

Code:
if ($rec{'Balance'}) {
print qq|
<TR><TD align=right>Balance:</td><td>$rec{'Balance'} yards</td></tr>
|;
} else {

print qq| |;

}

What am I doing wrong?

Thanks,

John
Quote Reply
Re: [jgold723] conditional display of field In reply to
That looks like it should work... you don't even need the "else" part.

What kind of field is "balance" ? Could there be something getting in the field (such as a space)?

Try doing: if ($rec{'Balance'} ne "") as way of troubleshooting and see what happens (- its the same thing so you should get the same result)

I'm just curious if that makes any difference.
Quote Reply
Re: [jgold723] conditional display of field In reply to
If you can't figure out what the problem is, try adding

Code:
print length($rec{'Balance'});

That'll tell you if there's something there that doesn't appear to be.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] conditional display of field In reply to
Thank you for the feedback -- I'll give both of those items a try.

I did open the database file in a text editor and I can't see anything in the field, except a return. Balance is an alpha field and it's the last in the array, so there's no following pipe, just the return.

John
Quote Reply
Re: [JPDeni] conditional display of field In reply to
Hi JPDeni --

I did the print command and it came back with a "1". But when I open the database file, there is nothing there, except the return (I can display invisible characters, spaces, etc. in my text editor).

So is the return throwing off the code? Is there a way to code around that?

Thanks,

John
Quote Reply
Re: [Watts] conditional display of field In reply to
Did that -- but no difference.

Thanks,

John
Quote Reply
Re: [jgold723] conditional display of field In reply to
Try changing your conditional statement to

Code:
if (length($rec{'Balance'})>1) {


It probably is the return that's being picked up, especially since it's at the end of the row. This should get around the problem.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] conditional display of field In reply to
Many thanks -- that did it!

FYI -- after the success with your code, I went back and tried this for the conditional statement:

if ($rec{'Balance'} ne " ")

with a single space between the quotes. That seems to work as well.

Many thanks for your help and the help of everyone else on this forum!

John