Jump to content

Linking To Image Directory?


crazylegseddie

Recommended Posts

I currently have images i.e pd_thumbnail in the database located in a 'images/product' directory. These images will only show if I copy them to where the script executes. How do I set up my script to read the images from the specified directory. Currently my script to read the images is

[code=php:0]
$productUrl; ?>"><img src="<?php echo $row['pd_thumbnail']; ?>"

[/code]

Do I need to make a variable of pd_thumbnail to specify a directory?

ANy help on this will be very good

THX
Link to comment
https://forums.phpfreaks.com/topic/16483-linking-to-image-directory/
Share on other sites

sure,

[code=php:0]
$query = "SELECT * FROM ....";  //COmplete this
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
  if (!@$row['pd_thumbnail']) {
      // display noimage.jpg
  } else {
      echo "<img src='".$row["pd_thumbnail"]."' />";
  }
}
[/code]
Thx for reply but Im finding it hard to link what you have done to my script as it is displayed a lot different as I use the image as a URL ie.:

[CODE]
<?php
$result = mysql_query('SELECT pd_name, MAX(pd_id), pd_thumbnail
FROM tbl_product GROUP BY pd_id desc limit 1') or exit(mysql_error());
$row = mysql_fetch_assoc($result);
$productUrl = 'categories.php?c=17&p='. $row['MAX(pd_id)'];
?>
<a href="<?php echo $productUrl; ?>"><img src="<?php echo 'images/product/'.$row['pd_thumbnail']; ?>"
[/CODE]

Any suggestions?
try this mate
[code]<?php
$result = mysql_query('SELECT pd_name, MAX(pd_id), pd_thumbnail
FROM tbl_product GROUP BY pd_id desc limit 1') or exit(mysql_error());
$row = mysql_fetch_assoc($result);
$productUrl = 'categories.php?c=17&p='. $row['MAX(pd_id)'];
$image='images/product/'.$row['pd_thumbnail'];
if (!is_file($image)) {
$image='images/product/noimage.jpg';
}
?>
<a href="<?php echo $productUrl; ?>"><img src="<?php echo $image; ?>"
[/code]


so basicaly the image url is in $image and then we check to see if it isn't a file ands if it doesn't exist then we default to nopic.

Regards
Liam

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.