Gossamer Forum
Home : Products : DBMan : Customization :

print only if title=x

Quote Reply
print only if title=x
I'm trying to get a link to print of a word in the title=biology.

print qq| <a href="link">T</a> | if ($in{'title'} eq 'biology');

This only works if the user actually searches on the word "biology," but I want it to work regardless of the search, as long as "biology" is in the title. So if a user searches "Plant" and comes up with "Plant Biology", the "T" should show up.

thanks!
Sigrid

Quote Reply
Re: print only if title=x In reply to
I'm confused Smile are you trying to do a search and then only display the title?

Where in your html.pl file are you adding this? Is it for the search results?

Perhaps viewing the referenced threads in the FAQ noted below will help you find a solution, if not, please explain in more detail where you are putting the code you noted and when you want the title displayed.

Check under "Searching" and also maybe "Sorting".

Hope this helps

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: print only if title=x In reply to
No, I'm trying to display a link next to the record, but only if the record has biology in the title. The title will display regardless.

I'm putting it in sub html_record

For example, if someone looks for something,and the results have two records with "biology" in the title, those two records would also have the link "T" next to them. The others would just have no link. The user wouldn't have to search on "biology" to make the T appear (that is happening now).

Then, I might want to make link "B" appear if the titles have "zoology" in them, but let's just start with the Biology links.

thanks for the help.

Quote Reply
Re: print only if title=x In reply to
p.s. here's my whole sub, if that helps.

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.

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';

print qq|

<table width=600 border=1 bgcolor="#ffffcc" cellpadding=2 cellspacing=0>
<tr><td width=300><$font>$rec{'JournalName'}</Font>
<$font>$rec{'ISSN'}</Font></td><td width=150><$font>$rec{'FT'}</Font> $Comments</td><td width=150><a href="$rec{'url'}">$rec{'Database'}</a></Font></td></tr></table>

|;

###############BIOLOGY LINKS ##############

print qq|


T

| if ($in{'title'} eq 'biology');


}

Quote Reply
Re: print only if title=x In reply to
Okay let's try this:

This is assuming that you want to show a different link depending on the title field .. and it will be printed next to the title.

You will have alot of titles and links you could define your links in your .cfg file such as:

$linkT = '<a href="link">T</a>';
$linkZ = '<a href="link">Z</a>';

and then can try using in your html_record:

if ($rec{'title'} eq "biology") {
print qq| $rec{title} $linkT|;
}
elsif {
if ($rec{'title'} eq "zoology") {
print qq| $rec{title} $linkZ |;
}
else {
print qq| $rec{title} |;
}

Or if you just have a few you can try:

if ($rec{'title'} eq "biology") {
print qq| $rec{title} <a href="$linkT">T</a>|;
}
elsif {
if ($rec{'title'} eq "zoology") {
print qq| $rec{title} <A HREF="$linkZ">Z</A> |;
}
else {
print qq| $rec{title} |;
}

You would need to be sure that your Title fields are the right case .. Meaning if it's a selection field and you actually have Biology and Zoology then make sure you if statements matches the field name exactly.

Mind you I'm not a programmer .. but give this a try and let me know if you have any luck.

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: print only if title=x In reply to
Thanks, I tried that, and several variations (I'm trying to learn some programming, but I'm not very good yet), and I'm geting a syntax error:

./journalfind.pl line 106, near "elsif {"

Quote Reply
Re: print only if title=x In reply to
I also tried:

print qq| T | if ($rec{JournalName} eq 'biology');

And nothing showed up at all... I mean, my regular results showed up- I didn't get an error, nor did I get a T by the journal names comtaining biology in the title. JournalName is the correct field name. I tried it with and without single quotes around it. I tried biology with a capital B and with lowercase. Nothing.

Quote Reply
Re: print only if title=x In reply to
I'm not a programmer either, but I always thought that "if"-conditionals should *precede* the command block which is to be executed when the condition is true. So I would try:

if ($rec{'title'} eq "biology") {
print qq|T|;}

In order to also include "plant biology", you could try:

if ($rec{'title'} =~ /biology/) {
print qq|T|;}

This means that the value of $rec{'title'} is a string which contains "biology" as a separate word, so you would get "plant biology", but not "microbiology". To also get results for "microbiology", you might use "/.*biology/" instead of "/biology/". The dot is a wildcard for any one character, and the asterisk indicates any number of occurrences. If you want to learn more on how to code regular expressions, do a websearch on "pearl regular expressions", and you'll find plenty of tutorials.

best,

kellner
Quote Reply
Re: print only if title=x In reply to
For

"elsif {
if ($rec{'title'} eq "zoology") {
print qq| $rec{title} <A HREF="$linkZ">Z</A> |;
}"

in the above code, write

"elsif ($rec{'title'} eq "zoology") {
print qq|$rec{title} <A HREF="$linkZ">Z</A>|;
}"

That should take care of the syntax error.




kellner
Quote Reply
Re: print only if title=x In reply to
I finally got this to work:

print qq|<b> T | if ($rec{'JournalName'} =~ "Biology");

Kellner, thank you, what you had didn't work for some reason, but it helped me make the above code which did work, and it will help if I want to truncate, etc. Thank you Lois, too.

Quote Reply
Re: print only if title=x In reply to
Good to know that this works. I am a bit puzzled by the part "=~ "Biology"" though. As far as I understand perl (which is admittedly not very far), the matching operator "=~" only works with regular expressions, that is, with expressions within slashes like "/test/". It does *not* work with strings inside quotation marks. If I am right, and if your code actually works, then the tilde after the equation will probably simply be ignored, and the code will be evaluated just like "= "Biology". In which case the condition would not turn out true for "microbiology". If it *does* turn out true for "microbiology" as well, then I must have been wrong.

By the way, I hope you didn't forget to close that bold-tag in your code.

Best,





kellner
Quote Reply
Re: print only if title=x In reply to
I used this exact code, and it works:

print qq|<td><$font><a href="$rec{'OffCampus'}">Off Campus</a></font></td> | if ($rec{'OffCampus'} =~ "http");


It prints that table cell only if the OffCampus field has a url in it, even though the url is http://....

I don't know if it would work of the url was shttp://... but I don't need to know at this point.

thanks for the tips!
Sigrid

Quote Reply
Re: print only if title=x In reply to
... it wouldn't work, but as you don't need to know, I won't tell you why Wink ...

cheers,

kellner