crazylegseddie Posted August 3, 2006 Share Posted August 3, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/16483-linking-to-image-directory/ Share on other sites More sharing options...
shocker-z Posted August 3, 2006 Share Posted August 3, 2006 $productUrl; ?>"><img src="<?php echo 'images/product/'.$row['pd_thumbnail']; ?>" If you are in the directory under images that is..That should work Quote Link to comment https://forums.phpfreaks.com/topic/16483-linking-to-image-directory/#findComment-68766 Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 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"]."' />";} Quote Link to comment https://forums.phpfreaks.com/topic/16483-linking-to-image-directory/#findComment-68767 Share on other sites More sharing options...
crazylegseddie Posted August 3, 2006 Author Share Posted August 3, 2006 thx for quick response. Prob solved :) Quote Link to comment https://forums.phpfreaks.com/topic/16483-linking-to-image-directory/#findComment-68783 Share on other sites More sharing options...
crazylegseddie Posted August 5, 2006 Author Share Posted August 5, 2006 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' Quote Link to comment https://forums.phpfreaks.com/topic/16483-linking-to-image-directory/#findComment-69789 Share on other sites More sharing options...
ignace Posted August 5, 2006 Share Posted August 5, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/16483-linking-to-image-directory/#findComment-69792 Share on other sites More sharing options...
crazylegseddie Posted August 5, 2006 Author Share Posted August 5, 2006 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_thumbnailFROM 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? Quote Link to comment https://forums.phpfreaks.com/topic/16483-linking-to-image-directory/#findComment-69818 Share on other sites More sharing options...
shocker-z Posted August 6, 2006 Share Posted August 6, 2006 try this mate[code]<?php$result = mysql_query('SELECT pd_name, MAX(pd_id), pd_thumbnailFROM 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.RegardsLiam Quote Link to comment https://forums.phpfreaks.com/topic/16483-linking-to-image-directory/#findComment-70174 Share on other sites More sharing options...
crazylegseddie Posted August 12, 2006 Author Share Posted August 12, 2006 worked a treat.cheers mate Quote Link to comment https://forums.phpfreaks.com/topic/16483-linking-to-image-directory/#findComment-73675 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.