Gossamer Forum
Home : Products : DBMan : Installation :

Choosing a graphic from a search - Eliot

Quote Reply
Choosing a graphic from a search - Eliot
Eliot was kind enough to offer the following code for displaying a graphic depending on a search result (i.e. choose Rating 1 from a drop down,and get a .gif of one star, rating=>2 get two stars etc. in the search result)

I creating a rating field in default.cfg

Rating=> [10,'numer',1,1,1', "],

and formatted it as drop-down

%db_select_fields= ( Rating=>'1,2,3,4');

Now, I'm not sure WHERE the following code should GO in default.cfg (?) right after the definitions? (Radio fields, checkbox) just before authorization options? does it matter?


$rate_img1='img src="http://www.myserver.com/image1.gif" alt="1"'

$rate_img2='im src="http://www.myserver.com/image2.gif' alt="1"'

etc.

and also, WHERE in sub html_record routing do these go? Just where the Rating will print?

if($rec{'Rating'} ="1") {
print qql<$rate_img1>|;

etc.

wherever the Rating field <TD> is now?

Thanks, I couldn't get it to work without errors.

Lenny
Quote Reply
Re: Choosing a graphic from a search - Eliot In reply to
Using Carol's suggestion, here is what you do with the </td> tag and Rating word:

Code:
if ($rec{'Rating'}) {
print qq|<td><$font><b>Rating:</b></font></td> <td><$rate_img[$rec{'Rating'}]></td>|;
}

This will put the Rating and image into two different cells in the same row of your table.

BTW: You can put any HTML code between the following codes print qq| and | ; in perl scripts (and cgi scripts).

Wink

Hope this makes sense....

Wink

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

[This message has been edited by Eliot (edited October 06, 1999).]
Quote Reply
Re: Choosing a graphic from a search - Eliot In reply to
The following codes:

Code:
$rate_img1='img src="http://www.myserver.com/image1.gif" alt="1"'
$rate_img2='img src="http://www.myserver.com/image2.gif' alt="1"'

should go after the $font variables in the default.cfg file. You can also place the codes at the top of the html.pl after the $html_title variable. It really doesn't matter. Just so that it is not within a sub-routine in the html.pl file.

The problem with your if comparision codes is that you do not have a right bracket at the end. Also you have a 1 after the qq where a | character should be. The correct codes should look like the following:

Code:
if($rec{'Rating'} = "1") {
print qq|<$rate_img1>|;
}

Quote:
wherever the Rating field <TD> is now?

YES.

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: Choosing a graphic from a search - Eliot In reply to
May I make a suggestion just to make things a little easier?

Instead of

Code:
$rate_img1='img src="http://www.myserver.com/image1.gif" alt="1"'
$rate_img2='img src="http://www.myserver.com/image2.gif' alt="1"'

use

Code:
$rate_img[1]='img src="http://www.myserver.com/image1.gif" alt="1"'
$rate_img[2]='img src="http://www.myserver.com/image2.gif' alt="2"'

And then, in sub html_record, instead of

Code:
if($rec{'Rating'} ="1") {
print qq|<$rate_img1>|;

etc.

use

Code:
print qq|<$rate_img[$rec{'Rating'}]>|;

This will eliminate all the "if" statements. If it's possible for the Rating field to be empty, use

Code:
if ($rec{'Rating'}) {
print qq|<$rate_img[$rec{'Rating'}]>|;
}

It does the same thing, but using the array makes things a little more compact.


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





Quote Reply
Re: Choosing a graphic from a search - Eliot In reply to
Carol,

Thanks! That does make it a lot easier and also reduces chance for errors!

Cool!

Smile

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: Choosing a graphic from a search - Eliot In reply to
Yes, both work quite well. I had to figure out where to put the ending qq| for it to work.

Can I put the <td> tags anywhere around

if($rec{Rating'}="1){
print|<$rate_img1>|;

to make it line up right? I've had a little bit of trouble with my tables in the past <grin>.

Do you think this code will work equally as will with symbols like $, $$, $$$ and *,**,*** etc? I'm going to try it (fingers crossed) I feel daring.

Oh, but how do I get it to print the word Rating next to the graphic (where in the code to put it), and how can I narrow it down so searching for one $ doesn't bring up $$, $$$,$$$$ ?


THANKS Y'ALL!!

[This message has been edited by CyborgNY (edited October 06, 1999).]

[This message has been edited by CyborgNY (edited October 06, 1999).]
Quote Reply
Re: Choosing a graphic from a search - Eliot In reply to
Great thanks. It's perfect.

Any ideas about my other question??

(searching for $, and avoiding $$,$$$,$$$$)


Thanks!

Lenny
Quote Reply
Re: Choosing a graphic from a search - Eliot In reply to
What are you talking about? Do you have monetary values in your search form? Or are you referring the $ signs used in the Perl code that stands for variables. If it is latter, then you should know that the $ signs will not print out in the search form or results.

If it is not that, please be more specific about your question.

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: Choosing a graphic from a search - Eliot In reply to
I understand what he means, because I've looked at his site. Lenny has ratings for the restaurants that are $ $$ $$$ $$$$, based on how expensive they are. The trouble is, that searching for one $ returns all of the other records, too.

Would your "exact match" mod work here, Eliot?


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





Quote Reply
Re: Choosing a graphic from a search - Eliot In reply to
It probably would. In early testing stages of the Mod, I used special characters such as periods and number sequences.

For example:

Searching for values like:

1.0567a

and

1.0567b

and did show exact matches.

Yet, I already told CyborgNY about using the mod in the Discussion Forum. It has worked for other users, but for some reason it must not be working for CyborgNY.

But, of course, I did not test the Mod with characters like dollar signs.

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