Gossamer Forum
Home : Products : DBMan : Customization :

Need a hack for HTML.PL (to show items only if in DB)

Quote Reply
Need a hack for HTML.PL (to show items only if in DB)
Hi..
I need someone to tell me how to do this.

I am adding items to the DB, and some ofmy fields are Image1, Image2, Image3, Image4, Image5. So when I add an item, I can put 5 images with it. (to show items in greater detail). Now, problem....
When I go to display the record, I want to show them like Image1, Image2, and so on, ONLY if they are in the DB. If the field is blank, I want it to ignore the image and not show a hyperlink to click on.

Any idea how to do this?
I need to put some code into here
sub html_record { in the HTML.PL file
I would assume..

Thanks
Michele
Quote Reply
Re: Need a hack for HTML.PL (to show items only if in DB) In reply to
Okay. Now it's time for one of my (in)famous examples.

Let's start with a simple html_record:

Code:
print qq|
<TABLE>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserFirstName:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserFirstName'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserLastName:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserLastName'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserEmail:</FONT></TD>
<TD WIDTH="80%"> <$font><a href="mailto:$rec{'UserEmail'}">$rec{'UserEmail'}</a></td>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserCity:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserCity'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserState:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserState'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserCountry:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserCountry'}</Font></TD></TR>
</TABLE>
|;

For this database, the field UserEmail is optional, and I don't want it to print out if the user hasn't added their email address. I would make the changes as follows:

Code:
print qq|
<TABLE>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserFirstName:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserFirstName'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserLastName:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserLastName'}</Font></TD></TR>|;
if ($rec{'UserEmail'}) {
print qq|

<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserEmail:</FONT></TD>
<TD WIDTH="80%"> <$font><a href="mailto:$rec{'UserEmail'}">$rec{'UserEmail'}</a></td>|;
}
print qq|

<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserCity:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserCity'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserState:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserState'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserCountry:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserCountry'}</Font></TD></TR>
</TABLE>
|;

Make sense?

If you have two or more optional fields in a row, you can use something like this:

Code:
print qq|
<TABLE>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserFirstName:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserFirstName'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserLastName:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserLastName'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserEmail:</FONT></TD>
<TD WIDTH="80%"> <$font><a href="mailto:$rec{'UserEmail'}">$rec{'UserEmail'}</a></td>|;
if ($rec{'UserCity'}) {
print qq|

<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserCity:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserCity'}</Font></TD></TR>|;
}
if ($rec{'UserState'}) {
print qq|

<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserState:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserState'}</Font></TD></TR>|;
}
if ($rec{'UserCountry'}) {
print qq|

<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>UserCountry:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'UserCountry'}</Font></TD></TR>|;
}
print qq|

</TABLE>
|;


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





Quote Reply
Re: Need a hack for HTML.PL (to show items only if in DB) In reply to
What you can do is add the following codes in your sub html_record routine:

Code:
if $rec{'Field'} {
print qq|<a href="$db_script_link_url&ww=on&$db_key=$rec
{$db_key}&view_records=1"><img src="/path/to/image1.gif" alt="$rec{'Field'}"></a>
|;
}
else {
print qq| |;
}

Replace Field with name of the field that you want to link to. You can repeat these codes for the other images.

Hope this helps.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Need a hack for HTML.PL (to show items only if in DB) In reply to
thank you! thank you! thank you! thank you! thank you! thank you! thank you! thank you!
Michele :-)
Quote Reply
Re: Need a hack for HTML.PL (to show items only if in DB) In reply to
Hi JP & Eliot:

Ok,its been a while. Everything seems to look good with the coding you gave me.

However, I have a big problem... I can't seem to fix. Perhaps you can tell me where the error lies...

I login here
http://www.carouselcollectables.com/cgi/db.cgi?db=carousel
username = test
pass = test

Ok, so I go to add a record, I put
Category = Gallery of Previously Carved Carousel Horses
Name = Brown Rocking Horse
Description = Brown Rocking Horse, no descp.
Age = leave blank
Price = leave blank
Thumbnail = leave blank
Image1 = horse11.jpg
Image2-5 = leave blank

Now, when I add it.... for some STRANGE reason, it is showing "Image5" link.... It should not show that because I didn't tell the system there was a 5th image.

I do notice that occassionally when I try to add an item, there is a space inserted into the "Image5" text box, so I backspace it out.

Any idea where the problem could be?

My files are here for your viewieng..
http://www.carouselcollectables.com/config.txt
(carousel.cfg file)

http://www.carouselcollectables.com/html.txt
(html.pl file)

Any help would be GREATLY appreciated.
Thanks for your previous help getting this going!

Michele
Quote Reply
Re: Need a hack for HTML.PL (to show items only if in DB) In reply to
Hmm...I really don't have to look at your html.pl in-depth, but I did check the sub html_record routine and everything looks fine. And does seem that you have defined the Image5 variable.

The thing that confuses me is that your sub html_record_form looks like the default form that comes with DBMAN. Are you using autogeneration???

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------




Quote Reply
Re: Need a hack for HTML.PL (to show items only if in DB) In reply to
Well I dont know if I am using auto generation. How do I tell??

What exactly is auto generation?

You mean, of the pages? No, the pages are displayed by code that I put on there.

Michele
Quote Reply
Re: Need a hack for HTML.PL (to show items only if in DB) In reply to
Yes, Image5 is the last one.
I did add another field and the Image5 issue
went away.

Then I removed it because I do not need the extra field, but if that will solve my problem, then I definately will add it in, since I still have to add all items to the database.

Thanks
Michele
Quote Reply
Re: Need a hack for HTML.PL (to show items only if in DB) In reply to
Anybody got a better solution to this apparent bug?

------------------
The Immuatable Order of Modding
-=-=-=-=-=-=-=-
1. Read the FAQ, 2. Search the board, 2a. Search the board again, 3. ask the question, 4. back-up, 5. experiment, 6. rephrase question (or better yet, post solution to original question)
Quote Reply
Re: Need a hack for HTML.PL (to show items only if in DB) In reply to
 
Quote:
Then I removed it because I do not need the extra field, but if that will solve my problem, then I definately will add it in, since I still have to add all items to the database.

When you add or remove fields from the db_def hash, you need to also remove or add the field in your existing database.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------




Quote Reply
Re: Need a hack for HTML.PL (to show items only if in DB) In reply to
Yes, but the database was completely EMPTY. I reuploaded an empty DB, so that there would be no problems.

I still have the Image5 bug.
The last field has a space, even though it shouldn't....
As you can see, my config file has no spaces in there for the starting value.

Michele
Quote Reply
Re: Need a hack for HTML.PL (to show items only if in DB) In reply to
Is Image5 the last field defined in the your DB? I've noticed that DBMan *sometimes* does not recognize a null value in the last field, and I haven't been able to figure out if its a PC/Unix file conversion issue or a residual Y2K bug Wink or what... the quick and somewhat ugly solution is to add a "dummy" field to the end of the DB, naturally of length zero.

------------------
The Immuatable Order of Modding
-=-=-=-=-=-=-=-
1. Read the FAQ, 2. Search the board, 2a. Search the board again, 3. ask the question, 4. back-up, 5. experiment, 6. rephrase question (or better yet, post solution to original question)