I checked the other posts in this forum but couldnt find what im searching for.
¿How to make a php-nuke block that shows random image from 1 album and no one else?
I found a topic about making a block exclude other albums but i want to restrict (not exclude, that would make me change the block whenever i put a new album) AND it didn´t work anyways for me :(
THX in advance :)
$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid='".$albumnumber."'", $dbi);
$nbEnr = mysql_fetch_array($result);
$count = $nbEnr[0];
while ($stop<$numberpic)
{
srand(time()+$stop);
$random_number = rand(0, $count-1);
$result2 = sql_query("SELECT pid, aid, filepath, filename from cpg_pictures WHERE approved='YES', aid='".$albumnumber."' LIMIT $random_number,1", $dbi);
$picture = mysql_fetch_array($result2);
Ofcourse set $albumnumber to the labum you wanna view
Quote from: "DJMaze"$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid='".$albumnumber."'", $dbi);
$nbEnr = mysql_fetch_array($result);
$count = $nbEnr[0];
while ($stop<$numberpic)
{
srand(time()+$stop);
$random_number = rand(0, $count-1);
$result2 = sql_query("SELECT pid, aid, filepath, filename from cpg_pictures WHERE approved='YES', aid='".$albumnumber."' LIMIT $random_number,1", $dbi);
$picture = mysql_fetch_array($result2);
Ofcourse set $albumnumber to the labum you wanna view
sorry, must i save that code in a block-name.php way?
and to set the album i have to put a "$albumnumber = 10" first or what?
(im really stupid, i know)
in the coppermine.1.1.d.zip there are plenty of blocks ....
grab block-Random_pictures.php ans save it as block-oneRandom_Picture.php
then open it in an editor
change the line that reads
$numberpic=5; // you can change the number of pictures here
to the number of pics you want to see - 1 I think :-)
add a line
$albumnumber=4;
direct after that. Change the number to suit your needs...
change the line that reads
$result = sql_query("SELECT count(*) from cpg_pictures", $dbi);
to
$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid='".$albumnumber."'", $dbi);
change the line that reads
$result2 = sql_query("SELECT pid, aid, filepath, filename from cpg_pictures WHERE approved='YES' LIMIT $random_number,1", $dbi);
to
$result2 = sql_query("SELECT pid, aid, filepath, filename from cpg_pictures WHERE approved='YES', aid='".$albumnumber."' LIMIT $random_number,1", $dbi);
save it
use it
BIG Thanks... but... it doesnt work :roll: :cry: :roll: :( :oops:
Ur explanation was very clear but i cant see any image in the block :/
Here´s what comes in my edited file ¿ok?:
<?php
/************************************************************************/
/* PHP-NUKE: Web Portal System */
/* =========================== */
/* */
/* Copyright (c) 2002 by Francisco Burzi */
/* http://phpnuke.org */
/* */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License. */
/************************************************************************/
/* Block to fit perfectly in the center of the site, remember that not all
blocks looks good on Center, just try and see yourself what fits your needs */
if (eregi("block-Random_pictures.php", $PHP_SELF)) {
Header("Location: index.php");
die();
}
$numberpic=1; // you can change the number of pictures here
$albumnumber=10;
global $prefix, $dbi;
function truncate_string444($str)
{
$maxlength = 20; // maximum lenght of name in block
if (strlen($str) > $maxlength)
return substr($str, 0, $maxlength)." ...";
else
return $str;
}
$content="<center>";
$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid='".$albumnumber."'", $dbi);
$nbEnr = mysql_fetch_array($result);
$count = $nbEnr[0];
while ($stop<$numberpic)
{
srand(time()+$stop);
$random_number = rand(0, $count-1);
$result2 = sql_query("SELECT pid, aid, filepath, filename from cpg_pictures WHERE approved='YES', aid='".$albumnumber."' LIMIT $random_number,1", $dbi);
$picture = mysql_fetch_array($result2);
$img = "<img src=\"{$picture['filepath']}thumb_{$picture['filename']}\" border=\"0\">";
$content .= "<a href=\"modules.php?name=coppermine&file=displayimage&album=random&cat=&pos=-{$picture['pid']}\">$img<br>" . truncate_string444($picture['filename']) . "</a><br><br>";
$stop++;
}
$content .= "<br><a href=\"modules.php?name=coppermine\">Go to gallery</a></center>";
?>
¿Any Failures? ¿Any Idea?
Right idea, but a small error:
$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid='".$albumnumber."'", $dbi);
should be$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid=$albumnumber", $dbi);
and$result2 = sql_query("SELECT pid, aid, filepath, filename from cpg_pictures WHERE approved='YES', aid='".$albumnumber."' LIMIT $random_number,1", $dbi);
should be$result2 = sql_query("SELECT pid, aid, filepath, filename from cpg_pictures WHERE approved='YES', aid=$albumnumber LIMIT $random_number,1", $dbi);
change the comma to "and" ind the query
... approved='YES' and aid= .-.-.
see it in all its glory at www.ally.sigi-2.de :-)
Well M8´s Big Thanks !!!
Now it works !
I´ll put here the code for anyone in future that needs this ¿ok? :)
<?php
/************************************************************************/
/* PHP-NUKE: Web Portal System */
/* =========================== */
/* */
/* Copyright (c) 2002 by Francisco Burzi */
/* http://phpnuke.org */
/* */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License. */
/************************************************************************/
/* Block to fit perfectly in the center of the site, remember that not all
blocks looks good on Center, just try and see yourself what fits your needs */
if (eregi("block-Random_pictures.php", $PHP_SELF)) {
Header("Location: index.php");
die();
}
$numberpic=1; // you can change the number of pictures here
$albumnumber=10;
global $prefix, $dbi;
function truncate_string444($str)
{
$maxlength = 20; // maximum lenght of name in block
if (strlen($str) > $maxlength)
return substr($str, 0, $maxlength)." ...";
else
return $str;
}
$content="<center>";
$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid=$albumnumber", $dbi);
$nbEnr = mysql_fetch_array($result);
$count = $nbEnr[0];
while ($stop<$numberpic)
{
srand(time()+$stop);
$random_number = rand(0, $count-1);
$result2 = sql_query("SELECT pid, aid, filepath, filename from cpg_pictures WHERE approved='YES'AND aid=$albumnumber LIMIT $random_number,1", $dbi);
$picture = mysql_fetch_array($result2);
$img = "<img src=\"{$picture['filepath']}thumb_{$picture['filename']}\" border=\"0\">";
$content .= "<a href=\"modules.php?name=coppermine&file=displayimage&album=random&cat=&pos=-{$picture['pid']}\">$img<br>" . truncate_string444($picture['filename']) . "</a><br><br>";
$stop++;
}
$content .= "<br><a href=\"modules.php?name=coppermine\">Go to gallery</a></center>";
?>