Jump to content


Photo

Linking To Image Directory?


  • Please log in to reply
8 replies to this topic

#1 crazylegseddie

crazylegseddie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 03 August 2006 - 06:51 PM

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

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


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

ANy help on this will be very good

THX

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 03 August 2006 - 06:53 PM

$productUrl; ?>"><img src="<?php echo 'images/product/'.$row['pd_thumbnail']; ?>"

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

That should work
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 06:56 PM

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"]."' />";
}
Tell me the problem, I will try tell you the solution

#4 crazylegseddie

crazylegseddie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 03 August 2006 - 07:29 PM

thx for quick response. Prob solved :)

#5 crazylegseddie

crazylegseddie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 05 August 2006 - 01:43 PM

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'

#6 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,430 posts
  • LocationBelgium

Posted 05 August 2006 - 01:48 PM

sure,

$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"]."' />";
   }
}


#7 crazylegseddie

crazylegseddie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 05 August 2006 - 03:15 PM

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.:

<?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']; ?>"

Any suggestions?

#8 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 06 August 2006 - 12:28 PM

try this mate
<?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; ?>"


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
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#9 crazylegseddie

crazylegseddie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 12 August 2006 - 01:45 PM

worked a treat.
cheers mate




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users