473,386 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

exclude empty image fields mysql / php

2
Sorry for this noob Huh question, but I am calling images from a database and I don't want to show the empty images.

Example webpage here

As you can see, there are 7 empty image fields left. How do I exclude empty fields in the code below

Code:
Expand|Select|Wrap|Line Numbers
  1.              <a href="<?php echo $listing_photo1; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo1; ?>" width="90" height="66" /></a>
  2.              <a href="<?php echo $listing_photo2; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo2; ?>" width="90" height="66" /></a>
  3.              <a href="<?php echo $listing_photo3; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo3; ?>" width="90" height="66" /></a>
  4.              <a href="<?php echo $listing_photo4; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo4; ?>" width="90" height="66" /></a>
  5.              <a href="<?php echo $listing_photo5; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo5; ?>" width="90" height="66" /></a>
  6.              <a href="<?php echo $listing_photo6; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo6; ?>" width="90" height="66" /></a>
  7.              <a href="<?php echo $listing_photo7; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo7; ?>" width="90" height="66" /></a>
  8.              <a href="<?php echo $listing_photo8; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo8; ?>" width="90" height="66" /></a>
  9.              <a href="<?php echo $listing_photo9; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo9; ?>" width="90" height="66" /></a>
  10.              <a href="<?php echo $listing_photo10; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo10; ?>" width="90" height="66" /></a>
  11.              <a href="<?php echo $listing_photo11; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo11; ?>" width="90" height="66" /></a>
  12.              <a href="<?php echo $listing_photo12; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo12; ?>" width="90" height="66" /></a>
  13.              <a href="<?php echo $listing_photo13; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo13; ?>" width="90" height="66" /></a>
  14.              <a href="<?php echo $listing_photo14; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo14; ?>" width="90" height="66" /></a>
  15.              <a href="<?php echo $listing_photo15; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo15; ?>" width="90" height="66" /></a>
Jun 1 '10 #1
3 2189
Dormilich
8,658 Expert Mod 8TB
the simple answer: don’t print 'em.

essentially, this is easier to accomplish with a function (among others):

Expand|Select|Wrap|Line Numbers
  1. function printLink($url = '')
  2. {
  3.     if (!empty($url))
  4.     {
  5.         $link = '<a href="%s" rel="lightbox[roadtrip]"><img src="%s" width="90" height="66"></a>';
  6.         printf($link, $url, $url);
  7.     }
  8. }
  9.  
  10. // ex:
  11. printLink($listing_photo1);
  12. // etc.
Jun 1 '10 #2
Sensas
2
Perfect, Thanks for the quick answer!

At this moment I solved it by:

Expand|Select|Wrap|Line Numbers
  1. <?php if(isset($listing_photo1) && $listing_photo1 != "") { ?><a href="<?php echo $listing_photo1; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $listing_photo1; ?>" width="90" height="66" /></a><?php  } ?>
  2.  
Works also.

Now the next thing is to make the uploader easier and ad an arrey ;-)
Jun 1 '10 #3
Dormilich
8,658 Expert Mod 8TB
sure, but you have to repeat it for every variable.
Jun 1 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
2
by: news.tele.dk | last post by:
Hi We have a SQL server 2000 SP4 on a windows 2003 2x3Ghz XEON 4 GB ram. We have a table looking like this with currently 6 rows. Total data is aprox 10 kb i all row all together. CREATE...
8
by: hemashiki | last post by:
hi i need help..how can i store image in mysql database and i want to retrive that image can anyone suggest plz
1
by: Koral | last post by:
Hi, I have a SELECT FROM TABLE query and in that table there is a field of type image. Result of this select goes throug internet do its destination. But in fact I need only to know if in this...
4
kaleeswaran
by: kaleeswaran | last post by:
hi! now i am using banking project.so i want to upload an image into mysql data base and j2ee using now. please any one give me the clue to uploade the image. thanks,
3
rajiv07
by: rajiv07 | last post by:
Hi to all, We can store image in mysql using MEDIUMBLOG data type.I want to know how to insert or select and store an image data type using perl. Is any idea Please Thanks. Regards ...
2
by: Eminosoft | last post by:
I am new to the php. plz tell that code for "how to store image in mysql database and also retrive that image"
4
by: foss | last post by:
HI all, I am able to upload the image as blob to mysql. but while displaying the image i cant display it properly . The code used for uploading image to mysql inserts data into mysql table.The...
1
by: santhanalakshmi | last post by:
hi, Please tell me ,how to insert an image in mysql ? for example ,my image is in the c drive under the image folder. We can use "BLOB datatype" for storing of ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.