Jump to content

Archived

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

crazylegseddie

Linking To Image Directory?

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

Share this post


Link to post
Share on other sites
$productUrl; ?>"><img src="<?php echo 'images/product/'.$row['pd_thumbnail']; ?>"

If you are in the directory under images that is..

That should work

Share this post


Link to post
Share on other sites
if you have the information stored in a database

[code=php:0]
$query = "SELECT * FROM ....";  //COmplete this
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
echo "<img src='".$row["pd_thumbnail"]."' />";
}

Share this post


Link to post
Share on other sites
Is there anyway I can use an IF statement with this script so If an image is not available it will automatically point to a 'images/product/noimage.jpg'

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.