Tag Cloud in PHP
Maggio 2, 2008
L’obiettivo di questo tutorial รจ creare una “nuvola” di TAG-link per rendere piu visibili gli articoli del vostro portale o blog.
Prima operazione: creare le classi CSS.
.tag5 { font-size: 7pt; }
.tag4 { font-size: 8pt; }
.tag3 { font-size: 9pt; }
.tag2 { font-size: 11pt; }
.tag1 { font-size: 14pt; }
Seconda operazione: calcolare il numero massimo e minimo di TAGS
$query = “SELECT Min(tag) as val_min, Max(tag) as val_max FROM tbl_Tags GROUP BY tag”;
$rs = mysql_query($query,$conn) or die(”Errore nella query:” . mysql_error());
while ($riga=mysql_fetch_array($rs)) {
$vmin = $riga['val_min'];
$vmax = $riga['val_max'];
}
Terza operazione: scalettare dimensioni e stampa a video
$query = “SELECT Count(tag) as conta tag FROM tbl_Tags GROUP BY tag”;
$rs = mysql_query($query,$conn) or die(”Errore nella query:” . mysql_error());
while ($riga=mysql_fetch_array($rs)) {
$dim = ceil(5*($vmax-$riga['conta'])/($vmax-$vmin));
print “<span class=’tag”.($dim).”‘>”.$riga['tag'].”</span> .”;
}
Leave a Comment
You must be logged in to post a comment.
Trackback this post | Subscribe to the comments via RSS Feed