Hi!
I have some difficulties with showing dynamic images from my database. :queasy:
Even when trying implementing headers, nothing really happens with the preview image (only showing one same image in every news coming up).
This is how it works. From my index.php I make my database display (ordered by date) a news list. Every news have their own image stored (path stored in database).
I guess what I'm trying to do probably isn't the way to do it. I sure could need some help..
Here is a part from the output (I output all the news and images using a for loop)
//before this, I've started a for-loop and made a database connection. The imagepreview is a part of the for-loop, fetching every image from the table database and making it appear with it's news.
if ($row['imagename']) {
$image = "<img src='shownewimage.php' alt='somepicture'/>";
}
echo "</td><td style='float: right; text-align: right;'>$bilde<
I guess (in a for-loop) it's a bit more complicated than just making every image have their source 'shownewimage.php'. Anyway, here is the code in createnewimage.php (which I thought took every image stored and resampled it) I guess not.. Now it only outputs one same image..
include "function.inc.php";
$connection = connect("my_database");
$sql = "SELECT imagename, date_publicated, date_finished, newsid FROM newstable
WHERE date_publicated <= now()
AND ( date_finished >= now() OR date_finished = '0000-00-00' )
ORDER BY date_publicated DESC, newsid DESC";
$result = mysql_query($sql, $connection);
while ($row = mysql_fetch_array($result))
{
$anImage = "images/webimages/intern/" . $row['imagename'];
if ( strstr($anImage, 'jpg') || strstr($anImage, 'jpeg')) { $mainImage = imagecreatefromjpeg($anImage); }
elseif ( strstr($anImage, 'gif')) { $mainImage = imagecreatefromgif($anImage); }
elseif ( strstr($anImage, 'png')) { $mainImage = imagecreatefrompng($anImage); }
else { echo "unknown imagefile: $anImage"; continue; }
$width = 135;
$height = 75;
$mainWidth = imagesx($mainImage);
$mainHeight = imagesy($mainImage);
$image_p = imagecreatetruecolor($width, $height);
imagecopyresampled($image_p, $mainImage, 0, 0, 0, 0, $width, $height, $mainWidth, $mainHeight);
// Output
if ( strstr($anImage, 'jpg' || strstr($anImage, 'jpeg'))) { imagejpeg($image_p, null, 100); }
elseif ( strstr($anImage, 'gif')) { imagegif($image_p, null, 100); }
elseif ( strstr($anImage, 'png')) { imagepng($image_p, null, 100); }
}