Jump to content

[SOLVED] Displaying images stored in database


ryanwood4

Recommended Posts

Hi,

 

I'm using the code I wrote below - (I'm a novice, so it could be completely wrong) - to display images which are stored in a folder on a server. The url to the images are kept in a database: gallery2, table: g2_FileSystemEntity column: g_pathComponent

 

But I can't seem to make it work. I want the code to display an image, and link to the larger image in the gallery.

 

The gallery url for each image starts: http://www.f1times.co.uk/gallery2/gallery2Embedded.php?g2_itemId= and then after the equals each image has a unique id. This is under g_id column. This is what I want the image to link to when clicked.

 

The images themselves are stored here: ttp://www.f1times.co.uk/gallery2/g2data_b0f3726a/albums/ (the image file name is stored in the database I mentioned above)

 

Any help would be very helpful.

 

<?php
$con = mysql_connect("xxxx","xxxx","xxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("f1times_gallery2", $con);

$result = mysql_query("SELECT * FROM g2_FileSystemEntity ORDER BY g_id DESC LIMIT 0,1");

while($row = mysql_fetch_array($result))
  {
    $url = "http://www.f1times.co.uk/gallery2/gallery2Embedded.php?g2_itemId=" . $row['g_id'];
    $image = "http://www.f1times.co.uk/gallery2/g2data_b0f3726a/albums/" . $row['g_pathComponent'];
    echo "<a href='$url' target=_parent>"."img src="($row['$image'])."</a>";
    
  }

mysql_close($con);
?></tr></table>

Hi ryanwood4,

 

In your echo statement:

 

echo "<a href='$url' target=_parent>"."img src="($row['$image'])."</a>";

 

$row['$image'] does not exist and the whole line is not valid syntax anyway.  Change your code to read:

 

echo '<a href="'.$url.'" target="_parent"><img src="'.$image.'" /></a>';

 

Hope this helps

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.