forum.coppermine-gallery.net
Support => Italian (Italiano) => Closed boards => Language Specific Support => cpg1.4.x Italian (Italiano) => Topic started by: technozeus on December 04, 2007, 03:33:06 pm
-
Ho creato una piccola funzione che mi permette di visualizzare in home page (anycontent) gli ultimi 3 album inseriti con la relativa thumb prescelta.
Nulla di che si intende, ma metto il codice, potrebbe interessare a qualcuno :)
In include/function.inc.php, alla fine del file, prima di ?> ho aggiunto la funzione:
function get_pic_lastAlbum()
{
global $CONFIG;
$str = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td>
<center><big>Ultimi album inseriti:</big><br><br>
</td>
</tr>
<tr>
<td class=\"tableh2\">";
$query1 = "SELECT a.aid aid
FROM {$CONFIG['TABLE_ALBUMS']} AS a
ORDER BY aid DESC
LIMIT 0 , 3";
$result1 = cpg_db_query($query1);
while ($rowset1 = mysql_fetch_array($result1)){
$aid = $rowset1['aid'];
$query2 = "SELECT a.aid aid, p.filepath ppath, p.filename pname, a.title atitle
FROM {$CONFIG['TABLE_ALBUMS']} AS a, {$CONFIG['TABLE_PICTURES']} AS p
WHERE a.thumb = p.pid
AND
a.thumb =
(SELECT a.thumb
FROM {$CONFIG['TABLE_ALBUMS']} AS a
WHERE a.aid = $aid)";
$result2 = cpg_db_query($query2);
$rowset2 = cpg_db_fetch_row($result2);
mysql_free_result($result2);
$a_title = $rowset2['atitle'];
$a_num = $rowset2['aid'];
$p_name = $rowset2['pname'];
$p_path = $rowset2['ppath'];
$suffix = "thumb_";
$str = "$str
<center><h2><a href=\"{$CONFIG['site_url']}thumbnails.php?album=$a_num\">$a_title</a></h2><br><br>
<center><a href=\"{$CONFIG['site_url']}thumbnails.php?album=$a_num\"><img src=\"{$CONFIG['site_url']}/albums/$p_path$suffix$p_name\"</a><br><br><br>";
}
mysql_free_result($result1);
$str = "$str
</td>
</tr>
</table>";
return $str;
}
e in anycontent.php la richiamo con:
<?php
$rowsetin = get_pic_lastAlbum();
echo $rowsetin;
?>
credo si possa ottimizzare meglio il codice, per ora mi č venuta cosė.
Ciao a tutti.
-
Grazie per il contributo, aggiunto nelle nostre faq in italiano (http://forum.coppermine-gallery.net/index.php?topic=43605.msg207301#msg207301)
-
grazie a te!
-
ho modificato la prima query, quella che ritorna l'elenco degli ultimi 3 album inseriti:
$query1 = "SELECT p.aid as aid, max(p.ctime) as maxctime
FROM {$CONFIG['TABLE_PICTURES']} p
GROUP BY p.aid
ORDER BY maxctime
DESC
LIMIT 0,3";
Ora ritorna gli ultimi 3 album a cui sono state aggiunte immagini (quindi se creo un album ma non aggiungo immagini non me lo fa vedere, almeno non dovrebbe :P )
ora sto lavorando ad una paginetta con l'elenco della cronologia degli album inseriti.
Ciao