, Guest!
Already a Member? Login or Register.

Menu



Showcase


MAY 11, 2010 - LATEST DEVELOPMENT NEWS:  FlexCMS 3.2.1 RELEASED!!!!!

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 
Wolf


Posts: 59
 
Random photo album image in a blockAugust 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!
 
Wolf


Posts: 59
 
August 6, 2008 @ 2:40pm
OMGosh... that is SO COOL. Thanks heaps! You really rock.

Thanks,
Wolfie
 
welby


Posts: 32
 
Great Code SnippetAugust 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
 

Post Message 




Try & Buy FeedForAll - Easy to use RSS Feed Creator - great for iTunes users!

MEMBERS



FlexCMS eNews

To subscribe to our enewsletter, please enter your email address in the box below and click the "Subscribe" button.


Note:  You may easily remove yourself from the newsletter list at any time by following the instructions included with every mailing.



All Contents, Code, Scripts and Technologies Copyright 2003-2009 FlexCMS.
All Rights Reserved. Software License Agreement

Processing Time: 0.32317 seconds.
 
Management Login

Powered By FlexCMS
Powered By FlexCMS