Gossamer Forum
Home : Products : DBMan : Customization :

Not display empty fields?

Quote Reply
Not display empty fields?
Hi all,

I dont want to display a field in search results, if it is an empty field.

What do I have to do therefor?

For example:

If my db has 50 fields, but there were about 20-25 empty in every entry, I only want to display the not empty-ones in the search results.

Sorry for my bad english, Im german.

Pit

Quote Reply
Re: Not display empty fields? In reply to
Pit:

For each field you would like to have displayed only if it contains an entry in sub html_record or sub html_record_long
use the following as an example:


if ($rec{'name'}) {
print qq| <TR><TD>Name:</TD><TD>$rec{'name'}</td></TR> |;
}

if ($rec{'address'}) {
print qq| <TR><TD>Address:</TD><TD>$rec{'address'}</td></TR> |;
}

If there is no entry the field will not be displayed if empty. You have to set up each field that is not required and may be empty using this method.

Hope this helps Smile
Quote Reply
Re: Not display empty fields? In reply to
Yeah Pit, what LoisC said (only I couldn't figure out how to make the explanation really short!) Smile
Quote Reply
Re: Not display empty fields? In reply to
AJ:

I didn't realize you were still answering this thread, until I posted my response Smile

There was actually 2 other responses posted while I was preparing my reply Smile

I visited you site the other day, very nice!
Quote Reply
Re: Not display empty fields? In reply to
In my 'sub html_record' I have the following code that prints a field if it contains something or prints a space to fill the spot if the field is empty:

Code:
if ($rec{'Rank'}) { print "<$font2b>$rec{'Rank'}</td>";
} else { print " </td>"; }
if ($rec{'Last'}) { print "<td bgcolor=$bgclr><$font2b>$rec{'Last'}</a></td>";
} else { print "<td bgcolor=$bgclr> </td>"; }
if ($rec{'First'}) { print "<td bgcolor=$bgclr><$font2b>$rec{'First'}</td>";
} else { print "<td bgcolor=$bgclr> </td>"; }
if ($rec{'Serial'}) { print "<td bgcolor=$bgclr><$font2b>$rec{'Serial'}</td>";
} else { print "<td bgcolor=$bgclr> </td>"; }
if ($rec{'Graduated'}) { print "<td bgcolor=$bgclr><$font2b>$rec{'Graduated'}</td>";
} else { print "<td bgcolor=$bgclr> </td>"; }
if ($rec{'Platoon'}) { print "<td bgcolor=$bgclr><$font2b>$rec{'Platoon'}</td>";
} else { print "<td bgcolor=$bgclr> </td>"; }
if ($rec{'Served'}) { print "<td bgcolor=$bgclr><$font2b>$rec{'Served'}</td>";
} else { print "<td bgcolor=$bgclr> </td>"; }
if ($rec{'Vietnam'}) { print "<td bgcolor=$bgclr><$font2b>$rec{'Vietnam'}</td>";
} else { print "<td bgcolor=$bgclr> "; }

You can easily change the above to show something like:

Code:
if ($rec{'Last'}) { print "<td bgcolor=$bgclr><$font2b>$rec{'Last'}</a></td>"; } else { print ""; }

Which will print nothing if the field is blank. The 'else { print ""; } would actually be redundant because if ($rec{'Last'}) is empty, it doesn't print anything anyway. But if you need a format in a table or something and have to have some code print out if the field is blank, the above will work great.

Hope this helps,
AJ

I edited the CODE above so this message thread would'nt be so wide!


[This message has been edited by TheFew (edited May 02, 2000).]
Quote Reply
Re: Not display empty fields? In reply to
Hi TheFew,

'dont know, if it helps, I give you all another example of what I want to have:

On my left side there are standing the fieldnames, for example name, adress, age, tel, fax, and so on.

If someone has no tel and no fax, I dont want to see tel and fax on the left side and no empty field on the right.

So if someone has all of it, there are 5 fields, if no tel and no fax, there are only 3 fields displaying in the search result.

So I could have 100 fields on the left, if someone has all fields full, but not 90 empty fields on the right side, because the 100 fieldnames are on the left, if someone has only 10 fields full.

Hope my english is not to worst.

Pit
Quote Reply
Re: Not display empty fields? In reply to
No, I understand. If there is name, add, tel, fax, email fields, you want to see:

Name: John Doe
Address: 1234 Cherry Lane
Phone: (800) 555-5555
Fax: (800) 555-5556
Email: jdoe@email.com

If there is only name, tel, email you want to see:

Name: John Doe
Phone: (800) 555-5555
Email: jdoe@email.com

Right?

Here is what you need to do. I don't know what mods you have installed, but the following is from the ORIGINAL html.pl file from dbman.zip.

in 'sub html_record' replace each line with the appropriate code to check if a field is blank. Here is an example of the original code:
Code:
<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>URL: </FONT></TD>
<TD> <$font><A HREF="$rec{'URL'}">$rec{'URL'}</A></Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Type: </FONT></TD>
<TD> <$font>$rec{'Type'}</Font></TD></TR>

Change each <tr><td...</td></tr> line to:

Code:
if ($rec{'URL'}) { print qq|<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>URL: </FONT></TD>
<TD> <$font><A HREF="$rec{'URL'}">$rec{'URL'}</A></Font></TD></TR>|; }
if ($rec{'Type'}) { print qq|<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Type: </FONT></TD>
<TD> <$font>$rec{'Type'}</Font></TD></TR>|; }

Remember to close and open any print qq| statments before and after these changes. For example:

Code:
print qq| #the opening print to set up static code
<TABLE WIDTH="475" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#FFFFCC">
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>ID:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'ID'}</Font></TD></TR>
|; #close the print qq from above
if ($rec{'URL'}) { print qq|<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>URL: </FONT></TD>
<TD> <$font><A HREF="$rec{'URL'}">$rec{'URL'}</A></Font></TD></TR>|; }
if ($rec{'Type'}) { print qq|<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Type: </FONT></TD>
<TD> <$font>$rec{'Type'}</Font></TD></TR>|; }

print qq| #open print again
<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Popular:</FONT></TD>
<TD> <$font>$rec{'Popular'}</Font></TD></TR>
</TABLE>
|; #close print

The above will setup the <table> and always print the Record ID. Then, if there is a 'URL' it will print it, if not it won't. Same for 'Type'. Then it will always print the 'Popular' field, then close the table.

Work with the above to get your desired fields/results. I have a number of mods added such as alternate color for each line, short/long display, and some of my own touch! If you want to see how my results show up, go to:

http://www.thefew.com/...d&view_records=1

AJ
Quote Reply
Re: Not display empty fields? In reply to
Thanks Lois, I'm happy to hear that (makes me appreciate my effort when others like the results)! Hopefully we have helped Pit out!

Have a day!
AJ
Quote Reply
Re: Not display empty fields? In reply to
Hallo,

thanxs for you both a very lot.

But one more question:

Your modification requires, that I dont let the db-script make the htmls automaticly, but let make the htmls over the html.pl?

Pit
Quote Reply
Re: Not display empty fields? In reply to
Yes, the code given earlier does require that you create your own subroutines in the html.pl file. (Most of us who are on the board often forget that the autogenerate feature even exists. Smile )

However, there is a way to skip blank fields and to do some other things to with autogenerate. Go to http://www.jpdeni.com/...ods/autogenerate.txt and pickup and install the "Autogenerate Enhancements" mod.

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






Quote Reply
Re: Not display empty fields? In reply to
Autogenerate? Oh yeah, I forgot about that! Smile I tried it once and didn't like the output at all! I couldn't do all the neat mods and features with the autogenerate routine either! Sorry Pit...I'm used to writing my own code Smile!

AJ
Quote Reply
Re: Not display empty fields? In reply to
Hi,

thank all of you for your exellent help.

I also have done my own code now, because the autocode was not that, what I wanted to have.

Your mods are so exellent, most of them I dont understand untill now, but I'm learning fast:-) I hope so...

I'm new in this script, and I am happy to have such a nice board with such nice people and I hope, that in future I can help here also.

Thanxs

Pit