0

hi everyone, I am looking into a small problem I have with a mysql database.
At the moment users can upload upto 4 images per item.
I am using php to display the images from the database, but if a user has only uploaded 2 images
I am getting empty images displaying.

Is there a way to check if a mysql colum has data ? and if it has, display it
the data in each colum is the path to each image stored on the server
For example
itemimage01 (Coloum Name)
http://www.mydomainname.com/path/to/image/image.jpg

I am using the following to get a list of images

<?php 
// build and display image gallery
$sql = mysql_query("SELECT * FROM images WHERE uiid='$uiid'");

$img_list = '';

while($row = mysql_fetch_array($sql)){ 

    $img1 = $row['img1'];   
    $img_list .= "<img src='$img1' width='268' height='269' title='$title' alt='$title'/>";
    }
?>

Then displaying the images using php open and close brackets

Thanks in advance

Edited by happygeek: moved forum

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by smantscheff
0

Change your code to

if (strlen($img1))
    $img_list .= "<img src='$img1' width='268' height='269' title='$title' alt='$title'/>";

or better

if (file_exists($_SERVER['DOCUMENT_ROOT'] . $img1))
    $img_list .= "<img src='$img1' width='268' height='269' title='$title' alt='$title'/>";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.