- It’s easy to show random photo uploads from your PhotoPost gallery anywhere on your site. This thread has the details, skip to the end for the latest, and the PHP code snippet for random photos is:
<?php
$host = 'localhost';
$dbUser = 'root';
$dbPass = 'database-password';
$db = 'database-name';
mysql_connect("$host", "$dbUser", "$dbPass") or die(mysql_error());
mysql_select_db("$db") or die(mysql_error());
$result = mysql_query("SELECT id,cat,bigimage FROM pp_photos order by rand() LIMIT 1" ) or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
print "<a href=\"/photos/showphoto.php/photo/" . $row['id'] . "\"><img src=\"/photos/data/" . $row['cat'] . "/thumbs/" . $row['bigimage'] . "\"></a>";
}
?>
This entry was posted
on Friday, October 12th, 2007 at 2:47 am and is filed under Tips.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
October 19th, 2007 at 6:33 am
Keep in mind that those code snippet does not involve any security checks and will display photos from private albums or categories a user doesn’t have permissions for. Only on totally open system would this be effective. Also, it doesn’t account for copies of photos which would have their thumbnail stored other than in the original location.
This will work for some users; but others will want to use a snippet that accounts for copies and security. I can post something relevant up shortly.
October 26th, 2007 at 11:52 am
At Digital Photography Now we wrote our own code to do just this but it also limits the display to images with a rating of at least 8/10.
Ian