Good Afternoon All,
The recent threads about images got me to finally experiment with storing
into and retrieving/displaying images from a database.
Uploading and retrieval is fine, I'm just a bit uncertain about creating the
dynamic display part.
// getting the data out of the db
$imageCountinDB = 0;
$selectedData = @mysql_query("select title, imagedata from pictures order by
pid desc");
while ( $row = @mysql_fetch_assoc($selectedData )) {
$title[] = htmlentities( $row['title'] );
$imageBytes[] = htmlentities( $row['imagedata'] );
$imageCountinDB++;
}
// creating the an html table with one img tag per cell
if ( IsSet( $_GET['im'] ) && $imageCountInDB > 0 ) {
$imageOutputStr = "<table><tr>";
for ( $i = 0; $i < $imageCountinDB; $i++ ) {
$setID = $i + 1;
$imageOutputStr .= "<td><img src=?im=$setID
width=300></td>";
if ( $setID % 3 == 0 && $imageCountinDB > $setID ) {
$imageOutputStr .= "</tr><tr>\n";
}
}
$imageOutputStr .= "</tr></table>";
}
// associating the image data with the img tags
switch ($_GET['im']) {
case 1: header("Content-type: image/jpeg");
print $bytes[0];
exit ();
break;
case 2: header("Content-type: image/jpeg");
print $bytes[1];
exit ();
break;
(snip)
}
<html>
<body>
<?php echo $imageOutputStr; ?>
</body>
</html>
The question is, with all this happening in one page, is it possible to do
the last bit dynamically?
BTW, the core of the above was nicked from
http://www.wellho.net/solutions/php-example-php-form-image-upload-store-in-mysql-database-retreive.html
Thanks very much for reading this long post.
David