I do understand that sometimes the explanations can be difficult if English is not your first language. I'll try to explain it, but let me know if it doesn't work. (I just thought of a better way to do it anyway.
)
First I'll explain a little bit about Perl and how things are displayed. Whatever is going to actually appear on the web page must be "printed" to the page. In most of DBMan, the statement that is used to tell the script "print this" begins with
print qq| and ends with
|; By using
print qq|, the script can print out variables (things that start with a
$, like
$rec{'FieldName'}) and it can also print out quotation marks, which are necessary for things like URLs and image tags (
<a href="www.server.com/">).
Any commands that you want the script itself to execute must be outside of a
print qq| statement. Otherwise, the commands will be printed on the web page and the commands will not be executed.
Does this make any sense?
If you've followed me so far, you'll have a much better understanding of what actually is happening in the script and you can work with it much better.
The subroutine that displays the record information is
sub html_record. It starts with
Code:
my (%rec) = @_; # Load any defaults to put in the VALUE field.
($db_auto_generate and print &build_html_record(%rec) and return);
my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2';
All these lines are commands for Perl. The next line starts the printout on the html page.
print qq| You will probably have something you want to print before you check for whether something exists in a field -- <table><tr><td> tags, font tags, labels for the field -- lots of possiblities.
What I would do (if you haven't already) is to create the html_record subroutine as if every field would be printed. Don't worry at first about empty fields. If you are careful in the way you enter your field information, it will be much easier to edit later.
Here's a little example of the display portion of sub html_record for a database with four fields:
Code:
print qq|
<table>
<tr><td>ID:</td>
<td>$rec{'ID'}</td></tr>
<tr><td>Name:</td>
<td>$rec{'Name'}</td></tr>
<tr><td>Age:</td>
<td>$rec{'Age'}</td></tr>
<tr><td>URL:</td>
<td>$rec{'URL'}</td></tr>
</table>
|;
Once you have the display looking the way you want it to, then look at what you might want to leave out if the field for a particular record is blank.
Find the starting and ending points of the formatting you want to leave out. Insert three blank lines before and after that point. (If there are several fields you want to set up as optional, just do one at a time and test it before you do another one.)
Continuing with my example, I'm going to make the URL an optional field.
Code:
print qq|
<table>
<tr><td>ID:</td>
<td>$rec{'ID'}</td></tr>
<tr><td>Name:</td>
<td>$rec{'Name'}</td></tr>
<tr><td>Age:</td>
<td>$rec{'Age'}</td></tr>
<tr><td>URL:</td>
<td>$rec{'URL'}</td></tr>
</table>
|;
Go to the first blank line you made and enter
|; on that line.
On the next line, enter
if ($rec{'FieldName'} gt $db_defaults{'FieldName'}) { replacing
FieldName with the name of the field you want to test.
On the third blank line, enter
print qq| My example will now look like
Code:
print qq|
<table>
<tr><td>ID:</td>
<td>$rec{'ID'}</td></tr>
<tr><td>Name:</td>
<td>$rec{'Name'}</td></tr>
<tr><td>Age:</td>
<td>$rec{'Age'}</td></tr>
|;
if ($rec{'URL'} gt $db_defaults{'URL'}) {
print qq| <tr><td>URL:</td>
<td>$rec{'URL'}</td></tr>
</table>
|;
(Of course, yours won't have bold letters in it. I just put them there so you could see it more easily.)
Now go to the blank line after the optional section. Enter
|; on that line.
Go to the next blank line.
Enter a
} on that line.
Go to the other blank line and enter
print qq| on that line. My example now looks like
Code:
print qq|
<table>
<tr><td>ID:</td>
<td>$rec{'ID'}</td></tr>
<tr><td>Name:</td>
<td>$rec{'Name'}</td></tr>
<tr><td>Age:</td>
<td>$rec{'Age'}</td></tr>
|;
if ($rec{'URL'} gt $db_defaults{'URL'}) {
print qq|
<tr><td>URL:</td>
<td>$rec{'URL'}</td></tr>
|;
}
print qq| </table>
|;
It's all done.
Please let me know if you have any questions.
------------------
JPD
[This message has been edited by JPDeni (edited May 04, 1999).]