1
slyss
Myalbum random pic in just one line of code
  • 2008/5/11 17:17

  • slyss

  • Quite a regular

  • Posts: 343

  • Since: 2006/1/26


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 www.stefanosilvestrini.com *****/
function getPicGallery($myalbumNum$cid$random) {
    global 
$xoopsConfig;
    
$db =& Database::getInstance();
    
$myalbumNum trim($myalbumNum);
    if(
$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";
        else 
$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' />"
                
."</a>"
                
."</div>";
    return 
$object;
}


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

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


WHERE:

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

eg:

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


will display random pics from myalbum and cid = 1

If you need to see the original tutorial is here:http://www.xoopsitalia.org/modules/article/view.article.php/c1/72

Feel free to visit my page for other tutorials: www.stefanosilvestrini.com

bye!!!
[size=x-large]2008 Xoops Book[/size]

2
trabis
Re: Myalbum random pic in just one line of code
  • 2008/5/11 23:05

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


It´s a very nice hack slyss, thanks for sharing :)

3
slyss
Re: Myalbum random pic in just one line of code
  • 2008/5/12 6:21

  • slyss

  • Quite a regular

  • Posts: 343

  • Since: 2006/1/26


[size=x-large]2008 Xoops Book[/size]

Login

Who's Online

196 user(s) are online (129 user(s) are browsing Support Forums)


Members: 0


Guests: 196


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits