CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Tips & Solutions

 How I deal with 'blank' images

Print topic Send  topic

Author Message
DonB
Posted: 04/30/2007, 1:20 PM

I have a database which may or may not contain a photo in every row. I do
not want the 'big red X' to display when there is no image. I also want the
images to be a certain size (80px tall).

My solution:

Add two computed columns to the datasource that state:

IFNULL(photo,"no-picture.jpg') AS photo

and

CASE IFNULL(photo,-1) WHEN -1 THEN 1 ELSE 80 END AS photoheight

Then I put an Image control into the grid, and set it's data source to the
'photo' column. I edited the HTML to include the attribute height=""'.
Lastly, I right-clicked within the quotes, picked "Add Attribute" from the
popup menu, and chose the 'datasource column' for it's type, and
'photoheight' for it's value.

This results in a grid filled with either the real photo or
'no-picture.jpg'. And because the photoheight is selected as 1 when there
is a missing image, or 80 when there IS a picture, I get no big gaps of
blank space for the rows that have no photo.

Of course, this depends on the folder containing a photo file for every
record that specifies a filename, and one more picture that is 1x1 pixels
and transparent. If either of these fail, I would still see the 'big red
X'. But for me it works, and I don't have to bloat up the page with the
usual 'Visible = false' code in a Before Show event.

One final thought: If my photos were already 80 pixels tall, then it would
become a trivial issue, because I would not need to worry about the image
size, merely let 'no-picture.jpg' appear with no height specified. Since
it's just 1 pixel tall/wide the gaps take care of themselves.

My application is using MySQL for the database, which has the IFNULL and
CASE-WHEN-THEN-ELSE-END SQL syntax support.
Other databases may require altering the SQL syntax from what I used.
Microsoft Access doesn't implement the CASE syntax at all.

--
DonB

http://www.gotodon.com/ccbth


DonB
Posted: 05/24/2007, 5:45 PM

Further refining the concept: If the field is blank, treat it as if it was
NULL.

CASE photo
WHEN '' THEN 'no-picture.jpg'
ELSE
CASE IFNULL(photo,'no-picture.jpg') ELSE photo END
END

--
DonB

http://www.gotodon.com/ccbth


"DonB" <~ccbth~@gotodon.com> wrote in message
news:f15j2s$oq4$1@news.codecharge.com...
> I have a database which may or may not contain a photo in every row. I do
> not want the 'big red X' to display when there is no image. I also want
the
> images to be a certain size (80px tall).
>
> My solution:
>
> Add two computed columns to the datasource that state:
>
> IFNULL(photo,"no-picture.jpg') AS photo
>
> and
>
> CASE IFNULL(photo,-1) WHEN -1 THEN 1 ELSE 80 END AS photoheight
>
>

rstewart


Posts: 17
Posted: 01/11/2008, 7:42 AM

You could use client-side javascript's onerror also:

<img onerror="this.src='default.gif'" src="whatever.gif">
_________________
looking for work in a sunny country.
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.