Je galère un eu, je cherche à faire un Tag Cloud à partir des données d'une BDD déjà existante.
Cela fonctionne actuellement, mais :
1/ Ce n'est pas je pense la meilleure façon (requêtes ?)
2/ Je n'arrive pas à faire afficher le cloud en aléatoire.
Any idea ?
Code : Tout sélectionner
<div class="paragraphe">
<h2> Hashtags : Les catégories de legs </h2>
<ul class="tblcloud">
<?php
// Serveur
include 'moteurs/sql2-data.php';
// Nom de la table utilisee (ex : testmail) :
$table = "Destock";
// Connexion SQL
$connexion = mysqli_connect("$chemin_db","$login","$pass","$database");
// Tests de connexion
if ($connexion->connect_error) {
die('Erreur de connexion (' . $connexion->connect_errno . ') '
. $connexion->connect_error);
}
if (mysqli_connect_error()) {
die('Erreur de connexion (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
// Requetes SQL
// Compter les lignes
$select = $connexion->query ("SELECT * FROM $table"); // Check Global
$nbr = $select->num_rows; // Global
$hashtags = $connexion->query ("select `Hashtag`, count(*) as num from $table WHERE `Collection` = 'WDA' group by `Hashtag` order by count(*) desc LIMIT 30");
// while ($hashtag = $hashtags->fetch_assoc())
{
// determine the popularity of this term as a percentage
//$percent = floor(($hashtag['num'] / $nbr) * 100);
//echo $hashtag['Hashtag']." : ".$hashtag['num']." Sur ".$nbr." (".$percent.")<br />";
}
while ($hashtag = $hashtags->fetch_assoc())
{
// Determine the popularity of this term as a percentage
$percent = floor(($hashtag['num'] / $nbr) * 100);
// Si vide
if ($hashtag['Hashtag'] == '') $hashtag['Hashtag'] = "NonReference";
// Determine the class for this term based on the percentage
echo ("<li>");
if ($percent < 1):
echo "<font size='-2'>" . $hashtag['Hashtag'] . "</font>";
elseif ($percent >= 1 and $percent < 2):
echo "<font size='-1'>" . $hashtag['Hashtag'] . "</font>";
elseif ($percent >= 2 and $percent < 5):
echo "<strong>" . $hashtag['Hashtag'] . "</strong>";
elseif ($percent >= 5 and $percent < 10):
echo "<font size='+1'><strong>" . $hashtag['Hashtag'] . "</strong></font>";
elseif ($percent > 10):
echo "<font size='+2'><strong>" . $hashtag['Hashtag'] . "</strong></font>";
endif;
echo ("</li>");
}
?>
</ul>
</div>