|
 |
 Home > FlexCMS Support Forum > User Help > Code Snippets > Random photo album image in a block

FlexCMS Support Forum


Random photo album image in a block Started August 6, 2008 @ 1:13am by Wolf
 |
Post Message |
|
|
| Random photo album image in a block | August 6, 2008 @ 1:13am | O Great and Powerful Oz...
I'd like to pull a random image from a random photo album and display it in a block.
Would you have a down and dirty way of doing that?
Thanks, Wolf |
|
|
|
|
|
|
| |
DCSun Administrator

Posts: 539 |
|
|
| August 6, 2008 @ 1:21pm | Hey Wolfie,
You're in luck, we happen to have just the thing you're looking for:

Code
$query = "select * from `".$Settings['DBPrefix']."pg-Settings`"; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { $pgSettings[$row['Name']] = $row['Value']; } if ($pgSettings['StorageLocationHTTP'] == '') { $pgSettings['StorageLocationHTTP'] = $BaseURL.'/pg_images'; } if ($pgSettings['StorageLocationLocal'] == '') { $pgSettings['StorageLocationLocal'] = './pg_images'; }
$Extensions[2] = '.jpg'; $Extensions[3] = '.png'; $ThumbExtensions[2] = '-thumb.jpg'; $ThumbExtensions[3] = '-thumb.png';
if (substr($pgSettings['StorageLocationHTTP'],0,1) == '/') { $ImageBaseHTTP = $BaseURL.$pgSettings['StorageLocationHTTP']; } else { $ImageBaseHTTP = $pgSettings['StorageLocationHTTP']; }
$query = "select * from `".$Settings['DBPrefix']."pg-Images` ORDER BY RAND() limit 1"; $result = mysql_query($query) or die (mysql_error()); $row = mysql_fetch_array($result);
// figure out thumbnail dimensions $NewWidth = $pgSettings['ThumbMaxWidth']; $NewHeight = $pgSettings['ThumbMaxHeight']; $WidthRatio = $row['ImageWidth'] / $NewWidth; $HeightRatio = $row['ImageHeight'] / $NewHeight; if ($WidthRatio >= $HeightRatio) { $NewWidthCalc = number_format($row['ImageWidth'] / $WidthRatio, 0); $NewHeightCalc = number_format($row['ImageHeight'] / $WidthRatio, 0); } else { $NewWidthCalc = number_format($row['ImageWidth'] / $HeightRatio, 0); $NewHeightCalc = number_format($row['ImageHeight'] / $HeightRatio, 0); } $ImageWidth = $NewWidthCalc; $ImageHeight = $NewHeightCalc;
$query2 = "select * from `".$Settings['DBPrefix']."pg-Galleries` where RecordNumber='".$row['GalleryNumber']."' limit 1"; $result2 = mysql_query($query2) or die (mysql_error()); $row2 = mysql_fetch_array($result2);
print '<a href="'.$MainURL.'/photos/'.$row2['RecordNumber'].'.html" class="BlockColors"><img src="'.$ImageBaseHTTP.'/'.$row['FileName'].$ThumbExtensions[$row['FileType']].'" width="'.$ImageWidth.'" height="'.$ImageHeight.'" border="0" alt=""><br>'.$row2['GalleryTitle'].'</a>'; |
|
David

 |
 FlexCMS v3.2 Has Been Released! |
|
|
|
|
|
|
| |
|
|
| August 6, 2008 @ 2:40pm | OMGosh... that is SO COOL. Thanks heaps! You really rock.
Thanks, Wolfie
|
|
|
|
|
|
|
| |
|
|
| Great Code Snippet | August 10, 2010 @ 7:53pm | I just added this to one of my sites and its fantastic.
Thanks for sharing.
Simply the best CMS and support around.
welby |
|
|
|
|
|
|
|


|
|
 | |