Myalbum random pic in just one line of code
Category : Hacks
Published by slyss on 11-May-2008 17:18
Hi all

i have written a function to build random pictures blocks (from myalbum-p).

You need to include this into your: root/include/functions.php:

/****** hack by *****/
function getPicGallery($myalbumNum$cid$random) {
$db =& Database::getInstance();
$myalbumNum trim($myalbumNum);
$random != 1$sql "SELECT s.lid AS lid, s.ext AS ext FROM ".$db->prefix('myalbum'.$myalbumNum.'_photos')." s, ".$db->prefix('myalbum'.$myalbumNum.'_cat')." t WHERE s.cid = t.cid AND s.cid = ".$cid." ORDER BY s.lid DESC LIMIT 1";
$sql "SELECT s.lid AS lid, s.ext AS ext FROM ".$db->prefix('myalbum'.$myalbumNum.'_photos')." s, ".$db->prefix('myalbum'.$myalbumNum.'_cat')." t WHERE s.cid = t.cid AND s.cid = ".$cid." ORDER BY RAND() LIMIT 1";
$result $db->query($sql);
$myrow $db->fetchArray($result);
$object =     "<div style='text-align: center;'>"
."<a href='".XOOPS_URL."/modules/myalbum".$myalbumNum."/photo.php?lid=".$myrow['lid']."'>"
."<img src='".XOOPS_URL."/uploads/thumbs".$myalbumNum."/".$myrow['lid'].".".$myrow['ext']."' align='center' hspace='3' vspace='3' width='100px' />"

and then you can add a custom PHP block with this code:

echo getPicGallery('X''Y''Z');


- X: myalbum Number
- Y: cid number
- Z: 1 = random pic ; 0 = last inserted pic


echo getPicGallery('''1''1');

will display random pics from myalbum and cid = 1

Discussion into forum: ... id=288832#forumpost288832

If you need to see the original tutorial is here:

Feel free to visit my page for other tutorials: