Gossamer Forum
Home : Products : DBMan SQL : Discussion :

best way to display a db image in custom templates

Quote Reply
best way to display a db image in custom templates
Sorry if this is a dumb question...

I've got a table, and one of the fields is for uploading an image file. I notice in the default templates, the url used to display the image is:

http://www.example.com/path/to/db.cgi?cn=column_name&do=view_file&id=pk&db=table_name

Is that the best/only way to do that in a custom template? I know you can have image sources set to just about anything as long as it returns the proper information to the browser. But for some reason, I'm getting a lot of broken images with that kind of url. (Actually, even weirder, they appear correctly sometimes and broken other times, with no apparent rhyme or reason.) I'm not sure if this is some screw-up with the server, or whether there's a better url format I could be using?

As always, grateful for any suggestions. Thanks.

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] best way to display a db image in custom templates In reply to
Hi,

You can also display a image field by using:

<img src="db.cgi?db=table&do=view_file&cn=<%image_column%>&id=<%primary_key%>" width="59" height="90" vspace="7" hspace="7" border=1>

TheStone.

B.
Quote Reply
Re: [TheStone] best way to display a db image in custom templates In reply to
Thanks. That's basically what I'm using. I think it must be some sort of problem with the server that's making the images only display some of the time. No idea what that could be, though...

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] best way to display a db image in custom templates In reply to
Finally figured out what I was doing wrong...

I needed to add uid=default to the url. DBManSQL was returning a login error instead of the image, otherwise. The reason it sometimes seemed to display was that I was logged in as another user with a cookie set. Assuming a default user is allowed to view records, though, this is an effective fix.

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [TheStone] best way to display a db image in custom templates In reply to
stone this is the referred link of my issue:

http://www.gossamer-threads.com/...%3Dview_file;#229895


now....

SmileStone! how do i do also to show the image only if the image file exist in that other table and if there is no any image file not showing anything.

thanx

i mean using

<if %image%>

<%else%>

<%endif%>

thanx i was trying this and cannot pull the data!
KevinW ANDRE
webmaster@cyberbrickell.com
Quote Reply
Re: [kevinws] best way to display a db image in custom templates In reply to
Try this:

<%if image_column%>
<img src="db.cgi?db=table&do=view_file&cn=<%image_column%>&id=<%primary_key%>" width="59" height="90" vspace="7" hspace="7" border=1>
<%else%>
do something else
<%endif%>

TheStone.

B.
Quote Reply
Re: [kevinws] best way to display a db image in custom templates In reply to
I use this ->

Code:
<%if Graphic eq 'yes'%>
<img src="http://www.mysite.com/<%Picture%>.jpg" alt="Photo <%Pict%>" border="0">
<%else%>
<img src="http://www.mysite.com/nopicture.jpg" alt="If you have a picture of this balloon or more information, please contact us at our email-address" width="177" height="264" border="1">
<%endif%>


So there is then a picture displayed when there is a graphic. Hope this helpes.
Luc Van Geyte
Quote Reply
Re: [Luc1] best way to display a db image in custom templates In reply to
but if the picture is in another table? how do you do to pull the picture the the search results?

i try this and does not work either what Stone Says Above!
KevinW ANDRE
webmaster@cyberbrickell.com
Quote Reply
Re: [Luc1] best way to display a db image in custom templates In reply to
Smilei think there is must be a way to indicate that the imagefile field is from the other table not in the present one that display the search results.

the imagefile field is located in another table so how do i make the if to understand this? with the below sentence:



<%if imagefile%>

<%else%>
KevinW ANDRE
webmaster@cyberbrickell.com
Quote Reply
Re: [kevinws] best way to display a db image in custom templates In reply to
I assume that you have two tables:

tableA (CodeID, .....)
tableB (ID, file_name (file field),..CodeID);

In this case one record in tableA could have multiple images in tableB.

and a global:

sub {
my $codeid = shift;
my $results = $DB->table('tableB')->select({ CodeID => $codeid }, ['ID'])->fetchall_hashref;
return { loop_images => $results, hit_images => $#$results + 1 };
}

Now, the html code should be:

<%loop results%>
<%global_name($CodeID)%>
<%if hit_images%>
<%loop loop_images%>
<img src="db.cgi?db=tableB&do=view_file&cn=<%image_column%>&id=<%ID%>">
<%endloop%>
<%endif%>
<%endloop%>

Hope that helps.

TheStone.

B.