473,811 Members | 3,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieving an Image if Condition Not Met

I'm sure the answer is simple, but the solution is eluding me-I'm
not too good at the particulars of scripting. Maybe someone can point
me on the right path...

Here is the problem:

I have a string of php code that retrieves an image, in this case, an
image of a book cover from Amazon.com. This works perfectly well,
unless, there isn't an image of the book on Amazon's server. When
there's no image, a blank hole appears on the final page. What I
would like to happen is, if the variable for the image isn't met
(i.e. no book cover image), a "No Image" image, from my server,
will load in its place.

Here is the code that retrieves the image:

<img border="0" src=<? echo $i['ImageUrlSmall'];?>>

Is there a way to include a command that will retrieve an image from
http://www.mysite.com/images/noimage.gif if the first condition is not
met?

If anyone can help me, I'd be grateful.

--Pete

May 21 '06 #1
2 1454
In article <11************ *********@i40g2 000cwc.googlegr oups.com>,
"Pete" <ca******@gmail .com> wrote:
I'm sure the answer is simple, but the solution is eluding me-I'm
not too good at the particulars of scripting. Maybe someone can point
me on the right path...

Here is the problem:

I have a string of php code that retrieves an image, in this case, an
image of a book cover from Amazon.com. This works perfectly well,
unless, there isn't an image of the book on Amazon's server. When
there's no image, a blank hole appears on the final page. What I
would like to happen is, if the variable for the image isn't met
(i.e. no book cover image), a "No Image" image, from my server,
will load in its place.

Here is the code that retrieves the image:

<img border="0" src=<? echo $i['ImageUrlSmall'];?>>

Is there a way to include a command that will retrieve an image from
http://www.mysite.com/images/noimage.gif if the first condition is not
met?

If anyone can help me, I'd be grateful.

--Pete


<?
$image = $i['ImageUrlSmall'] ? $i['ImageUrlSmall'] : "noimage.gi f";
?>
<img src="<?=$image ?>" />

Cleaned it up so it's easier to read. You can do it this way as well:

<img border="0" src="<? echo $i['ImageUrlSmall'] ? $i['ImageUrlSmall']
: "noimage.gif";? >">
--
Sandman[.net]
May 21 '06 #2
tim

Pete wrote:
I'm sure the answer is simple, but the solution is eluding me-I'm
not too good at the particulars of scripting. Maybe someone can point
me on the right path...

Here is the problem:

I have a string of php code that retrieves an image, in this case, an
image of a book cover from Amazon.com. This works perfectly well,
unless, there isn't an image of the book on Amazon's server. When
there's no image, a blank hole appears on the final page. What I
would like to happen is, if the variable for the image isn't met
(i.e. no book cover image), a "No Image" image, from my server,
will load in its place.

Here is the code that retrieves the image:

<img border="0" src=<? echo $i['ImageUrlSmall'];?>>

Is there a way to include a command that will retrieve an image from
http://www.mysite.com/images/noimage.gif if the first condition is not
met?

If anyone can help me, I'd be grateful.

--Pete


The condition is whether the file exists on amazons server.

One way to do check this is send a HTTP Head request to amazon's server
for the file, if the status code in the response is 200 then the file
exists at that location.

The php manual page for fsockopen will help you do it

Tim

May 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2283
by: ywg | last post by:
I'm generating an image using several PHP image routines: imagecreatefromjpeg, imagejpeg, etc. The PHP file containing these routines is meant to be included on web pages just like regular images, such as: <img src="image.php">. So far, all this works beautifully. Where I'm stuck is that I'd like to keep other web sites from including my image on remote web pages. I want the image to only display when rendered on pages from my web...
1
2006
by: Roman Kagan | last post by:
Hi everyone, I am successful in retrieving the image from the table (.TIF), however, the retrieved file does not work. It looks like an image file - extension, size and all, but the image is not visible. Any ideas? I'm including the first few lines (image opened with Notepad) of the file below. Please, help. """""
6
16135
by: Dean Slindee | last post by:
Does anybody have an actual example of retrieving an Image data type column from a SQL Server table using a dataset (not a datareader)? I would like to see the statements that would move the Image returned in the dataset to a picture box, like: For Each dr in ds.tables(0).rows Pic.Image = dr("ImageColumnName") 'not this simple! Next Thanks,
7
2065
by: Sirplaya | last post by:
I am retrieving images that I stored in SQL Server on my web pages in C#. I have no problem with the images displaying, however, I am trying to wrap the image with an <A HREF ..." and each time I try, it acts like the link is not even on the image. What is the proper way to do this? Thanks.
1
1817
by: Pathik | last post by:
Hi All, I have to get the values of "reading" and "value" elements of context Person/Category/Group/ser.These values must be on condition based,means I have to get the values of "reading" and "value" if entity="abc" and value="1" , and entity= "def" and value="2" at the Person/Category/Group/series/Key. My xml source file is as follows.
2
3943
by: Bjorn Sagbakken | last post by:
This is kind of silly, but I just cannot figure out why: In ASP.NET 2.0 I am retrieving images from a MS SQL server, and writing them as binary to a separate page as the url for image controls, everything by the book. I have been doing this a lot with VB. Now I am writing a new application in C#, and the strange thng is this: - it works well in debug mode - but not on the published folder on the same server (localhost) - image frames...
1
2443
by: san123456789 | last post by:
Hi, Im using a MS SQL server to store images... Im creating a windows form application using C#. I need to store and retrieve images from the database. This is my code to store images: pictureBox.Image = new System.Drawing.Bitmap(this.openFileDialog.FileName);
0
1859
by: velmani | last post by:
hi , i have problem with Retrieving image from DB i have a table with image datatype i store a file by using code as follows -------------------------------------------------- string strType; int intLength,intStatus; Stream ipStream; intLength = File1.PostedFile.ContentLength; strType = File1.PostedFile.ContentType;
2
2257
by: shivapadma | last post by:
i have inserted the image into database using the following code String driverName = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/"; String dbName = "hibernatetutorial"; String userName = "root"; String password = "root";
0
9731
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5556
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.