I'm slowing getting to grips with PHP, but I'm stuck on what appears to be the world's simplest problem.
I'm trying to write some code to dynamically build a page of clickable images from the contents of a DB table. I've successfully done the image upload and DB insert steps, but I'm now stuck on what I thought was going to be the easiest bit - displaying the images. I've written the following code:
$query = "SELECT fname, name, URL from banners";
$results = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($results))
{
extract($row);
$filename = "../banners/" . $fname;
echo "<a href=\"" . $URL . "\"><img src=\"" . $filename . "\"/></a>";
}
The problem I'm getting is that PHP doesn't seem to be able to handle the "../banners/" part of the string I'm trying to build up - the problem seems to be the last forward slash (I'm guessing that PHP thinks it's a regex delimiter rather than the character). The $fname statement should evaluate to something like "page1_01.jpg", so the $filename part should end up as "../banners/page1_01.jpg" and slot nicely into my "img src" tag.
If I leave the last forward slash in, then my <img src..> tag fails to evaluate and I get just the <a href> part. If I remove the final forward slash from "../banners/" and make it "../banners", then I get "../bannerspage1_01.jpg", but unfortunately that's not the path to my image.
I've tried various things like trying to escape the forward slash, but none of them have worked.
Any help would be greatly appreciated.
Thanks