PhotoPost Photo Sharing Gallery Sales PhotoPost Photo Sharing Gallery Sales Toll Free Phone Number
Mon-Fri 9am-4pm EST
  PhotoPost Photo Sharing Photo Gallery    Visualize community tm
vBulletin Forum UBB Ultimate Bulletin Board Forum
| | | | | | | | |
PhotoPost Blog

Tip: Show Random Photos Anywhere

  • 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>";
}
?>

2 Responses to “Tip: Show Random Photos Anywhere”

  1. Michael Says:

    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.

  2. Ian Says:

    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

Leave a Reply