You are here: Re: Building thumbnail page (mysql) « PHP Programming Language « IT news, forums, messages
Re: Building thumbnail page (mysql)

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация