Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: Displaying random image from coppermine gallery on website  (Read 2882 times)

0 Members and 1 Guest are viewing this topic.

apassio

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
    • Christine & Son's website
Displaying random image from coppermine gallery on website
« on: January 08, 2006, 03:20:01 pm »

Some time ago, with an earlier coppermine version, I used the code below to display random images of my gallery on my website:
http://www.dophan.com

Code: [Select]
// this was found in coppermine forum at http://coppermine.sourceforge.net/board/index.php?topic=1196.msg6902#msg6902
//***Enter Path information here***
//***absolute path to main coppermine directory***

$copperminepath = 'path';  //***YOU MUST CHANGE THIS***

//This connects to the mysql DB
//***change username and password below***

$MZrandompic = @mysql_connect('XXXX', 'XXXX', 'XXXX'); //***YOU MUST CHANGE THIS***

if (!$MZrandompic) { 
echo( '<p>Unable to connect to the ' . 
'database server at this time.</p>' ); 
exit(); 


//select photo DB
//***YOU MUST CHANGE THIS***

if (! @mysql_select_db('XXXX') ) {
die( '<p>Unable to locate the picture ' . 
'database at this time.</p>' ); 


//This gets a random picture record from the database and
//the picture's location and displays it

$MZresult = @mysql_query("SELECT * FROM cpg11d_pictures ORDER BY RAND() LIMIT 0,4"); 
if (!$MZresult) { 
die('<p>Error performing query: ' . mysql_error() . 
'</p>'); 


while ( $MZrow = mysql_fetch_array($MZresult) ) { 

// $albumid = $MZrow['aid'];  //This gets the picture's associated album name
$pos = $MZrow['pid'];      //This finds the picture's coppermine location

// echo('<P ALIGN=center>'); 

//old: target opens in new window
//echo('<a target = "_new" href="' . $copperminepath . '/displayimage.php?album=' . $albumid . 
//'&pos=-' . $pos . '">'); //make thumbnail clickable

//new: target opens in same window
echo('<a href="' . $copperminepath . '/displayimage.php?album=' . $albumid . 
'&pos=-' . $pos . '">'); //make thumbnail clickable

echo('<IMG SRC="' . $copperminepath . '/albums/');           //append base dir structure
echo($MZrow['filepath'].thumb_.$MZrow['filename'] .
     '" alt=' . $MZrow['filename'] . ' '. 'border=0 height=100>' . '</a> &nbsp;&nbsp;'); //outputs path from /userspics


//This displays the picture's album name and
//links it to the coppermine album

$MZalbumresult = @mysql_query("SELECT * FROM cpg11d_albums WHERE aid = '$albumid'"); 
if (!$MZalbumresult) { 
die('<p>Error performing query: ' . mysql_error() . 
'</p>'); 


while ( $MZalbumname = mysql_fetch_array($MZalbumresult) ) { 
echo('<FONT SIZE=1>');
echo('<P ALIGN=center>'); 

echo('<a href="' . $copperminepath . 
'/thumbnails.php?album=' . $albumid . '">' . 
$MZalbumname['title'] . '</a>' . '</p>'); 


if (! @mysql_select_db('XXXX') ) { 
die( '<p>Unable to reload the main website ' . 
'database at this time.</p>' ); 


?>


It's been working every until now. But after upgrading to CPG 4.1.3 I have the following question/issues:

1) Will the code above show pictures from albums which are password protected (new feature in CPG 4.1.3).
If yes, how can I prevent this?

2) How could I force image displayed to be only from my own albums (not from user gallery albums)

3) How can I choose only particular albums to be used in the random function?

Thanks
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Logged
Pages: [1]   Go Up
 

Page created in 0.016 seconds with 20 queries.