|
Posted by Pedro Graca on 10/28/06 21:17
Jane wrote:
> I need some help (php rookie) to build a thumbnail page using php.
> I'v a mysql database containing links to the original image files.
> No thumbnails created so far.
>
> It would be nice when the thumbnail contains a link to the original file :-)
So you already have the filenames in the database.
I'd add to the database a new column for the thumbnail
alter table XXX add column thumbnail enum('no', 'yes');
update table XXX set thumbnail='no';
Then I'd create the thumbnails for existing images:
<?php
$sql = "select filename from XXX where thumbnail='no'";
$res = mysql_query($sql);
while ($row = mysql_fetch_row($res)) {
create_thumbnail($row[0]);
$sql = "update XXX set thumbnail='yes' where filename='{$row[0]}'";
mysql_query($sql);
}
?>
where `create_thumbnail()` creates the thumbnail and stores it in a
"thumbs" directory.
When you want to display thumbnails just fetch them:
<?php
function thumbname($path) {
// input: http://www.example.com/images/photo00042.jpg
// output: http://www.example.com/images/thumbs/photo00042.jpg
return dirname($path) . '/thumbs/' . basename($path);
}
// ...
$sql = "select URL from XXX where thumbnail='yes' order by rand() limit 6";
$res = mysql_query($sql);
while ($row = mysql_fetch_row($res)) {
echo '<a href="' . $row[0] . '">';
echo '<img src="' . thumbname($row[0]) . '">';
echo '</a>';
}
?>
--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Navigation:
[Reply to this message]
|