Gossamer Forum
Home : Products : DBMan : Installation :

adding images per variable (possible 1-10 images)

Quote Reply
adding images per variable (possible 1-10 images)
Okay, I want to show images according to the number of selected variables. For example, I have a checkbox set up of several choices (a, b, c, d, e) and then showing images for all 5, But this is not a problem. The trouble comes when the user only selects 3 of the 5. In the table 3 images will show but the other 2 will be broken images. is there a way to show only the images for the choices that the user selected without having broken images? Maybe something like a "if per variable show a,b,c,d, and e images"?
Quote Reply
Re: adding images per variable (possible 1-10 images) In reply to
I'm not sure I understand. I'll tell you how I think it is and you can tell me if I'm wrong.

A user adds a record and can choose up to 5 images to display with his record. You have fields named something like "imagea," "imageb," "imagec," etc. If the user wants only three of the images to be displayed with is record, then the fields "imaged" and "imagee" would be empty, while the other three would have the name of the image to be displayed. Have I got it right?

If so, it's just a matter of some "if" statements:

Code:
if ($rec{'imagea'}) {
print qq|<img src="http://url/to/image directory/imagea">|;
}
if ($rec{'imageb'}) {
print qq|<img src="http://url/to/image directory/imageb">|;
}

And so on.

If I have completely misunderstood what you want to do, let me know and I'll see if I can come up with a different answer. Smile


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





Quote Reply
Re: adding images per variable (possible 1-10 images) In reply to
JP your great! you've basically understood what I was trying to say. I'm gong to give this a try tommorrow. It's already 3am over on this side of the Pacific Ocean. But I think that this is going to work just the way it is.

thanks Smile
Quote Reply
Re: adding images per variable (possible 1-10 images) In reply to
Hey JP we got a little problem. Umm it doesn't like the "pipe sign" in the code. Plus it's popping out errors where the code is fine.

I tried putting this into a table within the HTML.pl for the Long VIEW. could it be the IF statements. I'm not that knowledgable about HTML.

any clues?
Quote Reply
Re: adding images per variable (possible 1-10 images) In reply to
Did you end off the previous print qq| statement before you started the if statements? (I tend to forget to mention it, but if you have a print qq| statement to print out the table formatting and other fields, you have to end it by adding |; before you start your if statements.)

That's the most likely problem from what you describe.

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





Quote Reply
Re: adding images per variable (possible 1-10 images) In reply to
ahh -- NO Smile

I'll give it a shot today. Thanks JP !!!
Quote Reply
Re: adding images per variable (possible 1-10 images) In reply to
 Smile

It works !!!

No Ijust have to clean up my variables again.

Thanks JP
Quote Reply
Re: adding images per variable (possible 1-10 images) In reply to
Thanks JP, everything is fine but I was wondering can I do this with a check box format. ie, I have a check box setup of favorite fruits: apples, oranges, grapes and cherries. The user would pick whatever fruit they like. The data shows fine but how an I sepearte the data to show individual gifs for apples, oranges and cherries from the same data list. Or do I have to do it the hard way with radio boxes and input the data 1 by 1 so I can assign a gif to each individual variable.
Quote Reply
Re: adding images per variable (possible 1-10 images) In reply to
Again, I'm not real clear. What does the data look like in the field within the .db file? Are they all in one field, so it looks like:
apples~~cherries~~oranges
Or are they in separate fields:
apples|cherries|oranges

If it's the first way, you can say

Code:
|;
if ($rec{'Fruit'} =~ "apples") {
print qq|<img src="http://URL/to/apples.gif">|;
}
if (rec{'Fruit'} =~ "cherries") }
print qq|<img src="http://URL/to/cherries.gif">|;
}
etc.

If it's the second way, with each choice in its own field, it would be the way I showed you before.


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





Quote Reply
Re: adding images per variable (possible 1-10 images) In reply to
hmmm, I'm getting lost. Smile but this is ok!
My data is settup as:
fruit = apples|oranges|apples
Well that's how it prints out (I'm really clueless here)

Your tilde (~) "apples~~cherries~~oranges" solution is what I'm looking for, being apple to split the data into different images. Is it possible to the if statements without the tilde sign anyways or do I have to redo my html.pl again?

Thanks JP
Quote Reply
Re: adding images per variable (possible 1-10 images) In reply to
The structure of apples~~cherries~~oranges is what your actual .db file would look like if you have a multiple select field. When you read the record, ~~ is translated into your delimiter, so that $rec{'Fruit'} becomes apples|cherries|oranges.

You should be able to use the

if ($rec{'Fruit'} =~ "apples") {

structure for your display. The operator =~ means "includes," so if your variable $rec{'Fruit'} includes anywhere in it the word "apples," your apple gif will print.

Ooh. I just got another idea. At the time of printing, your field is "apples|oranges|cherries" right? You can do this really slick, if you name your .gif files the same names as your options.

Code:
@fruits = split(/\|/,$rec{'Fruit'});
foreach $fruit (@fruits) {
print qq|<img src="http://URL/to/graphics/$fruit">|;
}

This even works correctly if there is no entry in $rec{'Fruits'}.


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





Quote Reply
Re: adding images per variable (possible 1-10 images) In reply to
Hi JP, I've been trying what you suggested in your last post with slick version of printing images but now I'm getting a bunch of errors. 1.) do I have to use |; to stop the html and then use the @fruits method? 2.) you used @fruits and $rec{'fruit'} variables are they supposed to be different?
the debgging from DBMAN is popping out gibberish like:
Error Message : Error loading required libraries.
Check that they exist, permissions are set correctly and that they compile.
Reason: syntax error at /home2/carsten/.//public_html/cgi-bin/dbman/html.pl line 301, near ""#cccccc" height"
syntax error at /home2/carsten/.//public_html/cgi-bin/dbman/html.pl line 316, near "DoorPrice
Which of course don't even exist. any clues?
Quote Reply
Re: adding images per variable (possible 1-10 images) In reply to
 
Quote:
1.) do I have to use |; to stop the html and then use the @fruits method?

Yes. That's a perl command, not something that goes directly on the webpage.

Quote:
2.) you used @fruits and $rec{'fruit'} variables are they supposed to be different?

Yes. $rec{'fruit'} is the field in the record which holds your list of fruits. @fruits is an array that I made up to split the list into individual parts. The variable names don't have much to do with each other, but I intended to make them similar but a little different so you could tell them apart.

Quote:
[Errors] Which of course don't even exist. any clues?

I'd start looking at line 301 and go backwards. Of course, it's probably within the "fruity" routine you added. Wink Just from what you've posted, it looks to me like there may be a misplaced quotation mark or |.

If you want to post your html.pl script to your website, I'll take a look at it and see if I can find the error.


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





Quote Reply
Re: adding images per variable (possible 1-10 images) In reply to
 Smile nah make that a Wink

Ummm, I asked you about the stopping of the HTML but I completely forgot that I had to start it with the print qq| .... Dah that was rather lame of me.

interesting that a back slash turns out to be a YEN "\" mark on my Japanese made MAC.

All the things that went through my mind only to forget the basics. Thanks JP for getting me going again.