PDA

View Full Version : Resolved php display images



john0611
12-04-2009, 05:40 PM
Is there a way to tell mysql using php, if there is no data in the database (image.jpg) not to display the emty placeholder in browser where the image should be?


<?php
// query db
if (isset($_GET['id'])) {
$sql = "SELECT * FROM `products` WHERE id = '" . mysql_real_escape_string($_GET['id']) . "'"; // from products get id
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {

while ($row = mysql_fetch_assoc($result)) { //initial the loop

echo "<h4>" . $row['name'] . "</h4>"; // echo date results as format "h4"
echo "<p>" . $row['description'] . "</p>"; // echo content as p format "body text"
echo "<h5>Measurements: " . $row['measurements'] . "</h5>"; // echo content as p format "body text"

echo "<a href='img/products/{$row['filename']}' rel='lightbox' title='{$row['name']}'>";

echo "<img src='img/products/thumbnails/{$row['filename']} 'alt='{$row['name']}' title='{$row['name']}' width='156' height='109'></a>";

echo "<a href='img/products/{$row['filename2']}' rel='lightbox' title='{$row['name']}'>";

echo "<img src='img/products/thumbnails/{$row['filename2']} 'alt='{$row['name']}' title='{$row['name']}' width='156' height='109'></a>";

echo "<a href='img/products/{$row['filename3']}' rel='lightbox' title='{$row['name']}'>";

echo "<img src='img/products/thumbnails/{$row['filename3']} 'alt='{$row['name']}' title='{$row['name']}' width='156' height='109'></a>";

echo "<a href='img/products/{$row['filename4']}' rel='lightbox' title='{$row['name']}'>";

echo "<img src='img/products/thumbnails/{$row['filename4']} 'alt='{$row['name']}' title='{$row['name']}' width='156' height='109'></a>";

}
} else {
echo "Something is wrong!";
}
}
}
?>


Many thanks for any help and suggestions.

student101
12-06-2009, 11:20 PM
<?php
if (file_exists(img/products/thumbnails/{$row['filename4']}) &&
isset($row['filename4'])) {
... do stuff here
}
?>
OR

<?php
if (file_exists(img/products/thumbnails/{$row['filename4']}) &&
isset($row['filename4'])) {
... do stuff here...
}else{
... do opp. stuff here...
}
?>