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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.