Gossamer Forum
Home : Products : DBMan : Customization :

"If Then" question on Display

Quote Reply
"If Then" question on Display
I've got a question than is more Perl oriented rather than DB oriented, but the answer would be greatly appreciated.

I have four fields that if left blank, would not show up on the view record page. Currently I have

Code:
if ($rec{'Part'} && $rec{$'Description'} && $rec{$'Quantity'} && $rec{$'AproxCost'})

Which give the logic of, there must be something is each field in order to do the following script in the following { }.

An original posting showed using gt $db_default('FIELD'} to check for non default entries, but it only checks for one field...

Can anybody help with the script for checking to see if anything has been entered into any of the four fields, and if so - display the next "Then" statement.

Thanks!
-Dave
Quote Reply
Re: "If Then" question on Display In reply to
Forget the gt $db_default('FIELD'} thing. It is a really bad idea that I had before.

The reason I used it was that often people have things like 'http://' as a default for a URL field and using

if ($rec{'URL'})

will still print out even if the field only has the default http:// entered. A better choice is to delete the default before the record is added, if the user has not added anything.

The way to check for the existence of values in your fields is exactly as you have it.


------------------
JPD





Quote Reply
Re: "If Then" question on Display In reply to
Thanks for the quick reply. However, how do I display that line if only one item was entered into (any of) the field(s)? Something that would check the question,

If anything is in any of the four fields, display the HTML code. If there is nothing in any of the four fields (this is where you default check may come into play, although I don't use any defaults in my DB, others looking at this may), don't display the HTML code.

My example above only displays if something is in all of the fields.

Thanks!
Quote Reply
Re: "If Then" question on Display In reply to
You want to check each one individually?

Code:
if ($rec{'Part'}) {
print qq|$rec{'Part'}|;
}
if ($rec{$'Description'}) {
print qq|$rec{'Description'}|;
}
if ($rec{$'Quantity'}) {
print qq|$rec{'Quantity'}|;
}
if ($rec{$'AproxCost'}) {
print qq|$rec{'AproxCost'}|;
}

Is this what you needed?



------------------
JPD





Quote Reply
Re: "If Then" question on Display In reply to
That makes sense, but maybe if I show you in context...

Code:

if ($rec{'Part9'} && $rec{'Description9'} && $rec{'Quantity9'} && $rec{'AproxCost9'})

{ print qq|

<tr>
<td valign="top"><small>9.</small></td>
<td nowrap valign="top"><small>$rec{'Part9'}</small></td>
<td valign="top"><small> </small></td>
<td valign="top"><small>$rec{'Description9'}</small></td>
<td align="center" nowrap valign="top"><small>$rec{'Quantity9'}</small></td>
<td align="right" nowrap valign="top"><small>\$$rec{'AproxCost9'}</small></td>
</tr>

|;}

When this is run through, the HTML will only display if there is something in each of the the four fields, Part9, Description9, Quantity9, AproxCost9. My goal is to not display empty fields in a table where most people will only enter items on the first row. But I need to check to make sure that somebody didn't enter something into say, rows 3 and 4. If they did, I need to display the whole row.

This only gets a little complicated because I'm dealing with a table. With the layout of HTML, checking individual fields (36 in my case) will still display 9 rows of HTML. But if I can check for blank fields four at a time (in my example - one row of 4 fields) then I can simply not display the row.

I would have to assume that your solution would be a greatly more simplified way of doing this, if the only thing in my table was record fields. I'm going to try it and see if it is easier... But because of how HTML displays in tables - it's going to be somewhat bloated.

Thanks!
Quote Reply
Re: "If Then" question on Display In reply to
I think I'm getting confused. Smile

Let me see if I understand.

If there is a value in all four fields, print out the values.

If there is a value in one or more of the fields, print out the values that exist, plus blank cells.

If non of the four fields have a value, don't print anything.

Is that right?


------------------
JPD





Quote Reply
Re: "If Then" question on Display In reply to
Yes... That's it! As far as HTML goes, printing the blank fields doesn't matter.

In my mind's eye, you said

Quote:
If there is a value in all four fields, print out the values.

If there is a value in one or more of the fields, print out the values that exist, plus blank cells.

I would think of it as combining the two into:

Quote:
If there is a value in any of the four fields, print out the "chunk" of HTML (that HTML includes the values plus formating HTML).

Whew! I must be one of the most confusing people up here... I know that I caused you momments of cofusion the last time I asked some questions! But you're the greatest at helping once I can clear up my question!

Thanks!
Quote Reply
Re: "If Then" question on Display In reply to
 
Code:
if ($rec{'Part'} or $rec{$'Description'} or $rec{$'Quantity'} or $rec{$'AproxCost'})

I think that will give you what you want.

I do know that sometimes it's hard to define the problem exactly. That's why I ask so many questions. Smile


------------------
JPD