Gossamer Forum
Home : Products : DBMan : Customization :

if statements and blank lines

Quote Reply
if statements and blank lines
After searching for hours and trying every possible suggestion on the forum (tho none of them addressed my issue directly) - I surrender!!! I need help.

Here is my dilemma...

I have an address book sort of db going (with a lot of additional user info) and I want to print out a very simple list like so:

UserName (user spouse)
Street
City, State ZIP
<blank line>
next record

Problem is - I have several entries that do not have a street address entered - which is okay, but I don't want those records listed for this function.

So ... here's what I'm trying to do:

Read all the records
If the STREET is blank - skip this rec
Otherwise, print
UserName (IF there is a spouse listed, print it - ELSE leave this part blank)
Street
City State Zip

I hope I'm not being too confusing here??

Here's what I have - which works beautifully ... BUT it causes a line feed for every rec that has been "left blank" as a result of NO STREET field entry.

if ($rec{'STREET'} ne "" && $rec{'SE'} ne "") {
print qq|<td>$rec{'USER'} ($rec{'SE'})
$rec{'STREET'}
$rec{'CSZ'}
</td>|;
if ($rec{'STREET'} ne "" && $rec{'SE'} eq "") {
print qq|<td>$rec{'USER'}
$rec{'STREET'}
$rec{'CSZ'
</td>|;
}

Any help would be greatly appreciated!

keien

Quote Reply
Re: if statements and blank lines In reply to
keienb,

I think there is an easier way to do this. The code below will print the record if the $rec{'STREET'} contains data and print nothing if the $rec{'STREET'} is empty.

if ($rec{'STREET'})
{
print qq|
<td>$rec{'USER'} $rec{'SE'}
$rec{'STREET'}
$rec{'CSZ'}
</td>|;

}
else
{
print qq|

|;
}

Quote Reply
Re: if statements and blank lines In reply to
stiantot,

Just tried your code snippet - same problem that I've been having - when there are records that have an empty $rec{'STREET'} it isn't printing "nothing" ... it still prints a line feed.

This works fine when there aren't any "empty" records between two "good" ones ... but I have several places where there are 3 or more recs that should not be printed - so then there are THREE line feeds between recs in the display.

Any suggestions on how to eliminate this line feed on printing "nothing" ???

Thanks!

keien

Quote Reply
Re: if statements and blank lines In reply to
Try this one and see what happend.

Code:
if ($rec{'STREET'}) {
if ($rec{'SE'}) {
print qq|
<td>
$rec{'USER'} ($rec{'SE'})
$rec{'STREET'}
$rec{'CSZ'}
</td>
|;
}

else {
print qq|
<td>
$rec{'USER'}
$rec{'STREET'}
$rec{'CSZ'}
</td>
|;
}
}
rgds,

__________________________
http://anteromas.com
Trading Resources
Quote Reply
Re: if statements and blank lines In reply to
How about this :

if ($rec{'STREET'})
{
print qq|
<td>$rec{'USER'} $rec{'SE'}
$rec{'STREET'}
$rec{'CSZ'}
</td>|;

}
else
{
print "";
}

You should check the HTML output (source code). See what code (<p>,

etc.) that causes the linefeed. If you have the following code, or part of it, at the top of the sub html_record subroutine try removing it :

$rec{'whatever'} =~ s/\n\n/<P>/g;
$rec{'whatever'} =~ s/\n/<BR>/g;

Any luck?






Quote Reply
Re: if statements and blank lines In reply to
Still having the same problem
Here is my entire sub_html ... maybe you can see my error ?

sub html_record {
# --------------------------------------------------------
# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.
# This is the "short display" -- the list of records that are returned
# from a search.
&html_print_headers;
my (%rec) = @_;
($db_auto_generate and print &build_html_record(%rec) and return);
# create link to full display
# $record_number = ((($nh - 1) * $db_max_hits) + $i);

# $long_url = $ENV{'QUERY_STRING'};
#$long_url =~ s/\&nh=\d+//;
#$long_url =~ s/\&mh=\d+//;

#$long_url = "$db_script_url?$long_url&nh=$record_number&mh=1";

print "<TD>"; # do not remove this! It is necessary to make the records display properly

# Below is where you define what you want to appear for each record in the "short" display.
# You can make this whatever you want, and display as many fields as you would like.
# Choose which of the fields you would like for users to click on to reach the full display
# of records and use that field name in place of "Title" below.
#
# Be sure that you use <a href="$long_url"> for the link to your full record display.

# <-- Start of short display formatting -- >

if ($rec{'STREET'}) {
if ($rec{'SE'}) {
print qq|
$rec{'USER'} ($rec{'SE'})
$rec{'STREET'}
$rec{'CSZ'} |;
}
else {
print qq|
$rec{'USER'}
$rec{'STREET'}
$rec{'CSZ'} |; }}

# Add or remove columns as needed. Be sure you add the $long_url link to one of your fields

# <-- End of short display formatting -- >

print "</TD>"; # do not remove this! It is necessary to make the records display properly

}


Thanks,

Keien

Quote Reply
Re: if statements and blank lines In reply to
Try inserting:
$rec{'SE'} =~ s/<?.B>//g;

# after:
my (%rec) = @_;

If that doesn't work try:
Code:
print "$rec{'USER'} ($rec{'SE'})" if ($rec{'SE'});
print "$rec{'STREET'}" if ($rec{'STREET'};
print "$rec{'CSZ'}" if ($rec{'CSZ'});
Maybe you could give us the link to your page?

__________________________
http://anteromas.com
Trading Resources
Quote Reply
Re: if statements and blank lines In reply to
The problem could also be that that the <td></td> tags are placed outside the if statements. This means that they are printed even though the record is empty. Try deleting print "<TD>"; and print "</TD>"; and put them inside the if statement, like :

print qq|<td>
$rec{'USER'} ($rec{'SE'})
$rec{'STREET'}
$rec{'CSZ'} </td>|;

This COULD solve the problem, but I'm not sure. The URL for your page would help!



Quote Reply
Re: if statements and blank lines In reply to
Thanks guys, but neither suggestion has made any difference. The URL is on our corporate Intranet, so you wouldn't have access. Let me see if I can get a copy somewhere accessible and try to post that - may take me a bit.

The only thing I can think of that's still causing is some "built-in" sort of line feed. It seems like (ages ago) Carol had helped me with a printout where we had to FORCE a line feed. It was more of an "open db, look for XX, print it, close db, line feed, repeat" sort of thing.

Anyways, thanks for your help - I'll try and get this posted so you can see the whole thing.

Keien