Les archives de FluxBB.fr
Vous n'êtes pas identifié(e).
Pages : 1
Bonjour à tous,
Sur mon forum, j'ai installé feu Puntal. J'ai mis le bloc Archives. Le code de ce bloc crée des liens de la forme Année-mois. Quand on clique dessus, la page affiche le premier message de chaque topic ayant été posté pour cet Année-mois pour un forum donné.
Cool, ça marche bien. Seul hic, s'il n'y a pas eu de nouveau topic pour un mois donné, il y a quand même le lien, et la page renvoie les x dernières discussions depuis la date d'aujourd'hui en ordre décroissant. C'est beaucoup moins bien.
Alors, je sais, ici, ce n'est pas l'endroit du support de Puntal. Mais, avant tout je cherche à bien formulé ma requête sql qui puisse sortir quelque chose comme ça :
---------------------------
| total | année | mois |
---------------------------
| 3 | 2008 | 10 |
| 0 | 2008 | 09 |
| 5 | 2008 | 08 |
Je récupère la date de création du premier topic par cette requête (base de Puntal) :
$query = 'SELECT MIN(posted) FROM '.$db->prefix.'topics WHERE forum_id='.$id;Seul hic, c'est comment exploité ce résultat pour après obtenir ce que je veux ci-dessus puisque c'est un nombre de 10 caractères.
Si je converti ce nombre en prenant cette fonction :
$date = format_time(nombre, true);j'obtiens par exemple ceci : 02-12-2006
J'ai tenté avec cette requête :
$result2 = $db->query('SELECT COUNT(t.id) total, année(DATE_FORMAT("'.$date.'", "%Y")), mois(DATE_FORMAT("'.$date.'", "%m")) FROM '.$db->prefix.'topics t LEFT JOIN '.$db->prefix.'forums f ON t.forum_id=f.id WHERE t.forum_id='.$id.' AND t.moved_to IS NULL GROUP BY année(DATE_FORMAT("'.$date.'", "%Y")), mois(DATE_FORMAT("'.$date.'", "%m"))') or error('impossible de trouver le nombre de topics par mois', __FILE__, __LINE__, $db->error());Mais je n'obtiens pas le résultat escompté, puisque j'ai
---------------------------
| total | année | mois |
---------------------------
| 8 | NULL | NULL |
Pourriez-vous m'aider à formuler correctement la requête. Après, je pense que je trouverais facilement pour exploiter les résultats.
Merci de votre aide
Thierry
Dernière modification par Thiery (16-11-2008 19:25:12)
Hors ligne
Je reviens vers vous avec la solution.
En cherchant tout de même sur le forum, je me suis rendu compte que le bloc Archives de Puntal avait été repris de la Mode News_generator. Mais, je n'ai pas trouvé la solution pour autant.
Si ça peut aider quelqu'un, voici la modification à faire dans le fichier puntal/blocs/archives/index.php (Puntal 1.8.8)
Chercher :
// make a dynamic block
else {
// Generate monthly archives
$pt_year_end = intval(date('Y'));
$pt_month_end = intval(date('n'));
$pt_year_start = ($pt_month_end != 1) ? $pt_year_end : $pt_year_end-1;
$pt_month_start = ($pt_month_end != 1) ? $pt_month_end-1 : 12;
// How far back should we go?
$tmp_news_id = array();
foreach (explode(',',pt_mod_news_forum_id) as $id)
$tmp_news_id[] = " forum_id='".$id."'";
$query = 'SELECT MIN(posted) FROM '.$db->prefix.'topics WHERE ( '.implode(' OR ', $tmp_news_id).' ) ';
$result = $db->query($query) or fct::error($lang_puntal_mod_news['unable_get_posts'], __FILE__, __LINE__, $db->error());
$pt_history_limit = $db->result($result);
if ($pt_history_limit != null)
{
$pt_year_limit = intval(date('Y', $pt_history_limit));
$pt_month_limit = intval(date('n', $pt_history_limit));
echo "\t\t\t\t".'<ul>'."\n";
while ($pt_year_end > $pt_year_limit || $pt_month_end > $pt_month_limit)
{
echo "\t\t\t\t\t".'<li><a href="'.pt_portal_url.'index.php?/news/'.$pt_year_start.'/'.($pt_month_start > 9 ? $pt_month_start : '0'.$pt_month_start).'">'.$pt_year_start.'-'.($pt_month_start > 9 ? $pt_month_start : '0'.$pt_month_start).'</a></li>'."\n";
$pt_year_end = $pt_year_start;
$pt_month_end = $pt_month_start;
$pt_year_start = ($pt_month_end != 1) ? $pt_year_end : $pt_year_end-1;
$pt_month_start = ($pt_month_end != 1) ? $pt_month_end-1 : 12;
}
echo "\t\t\t\t".'</ul>'."\n";
}
}Remplacer par :
// make a dynamic block
else {
// Generate monthly archives
$pt_year_end = intval(date('Y'));
$pt_month_end = intval(date('n'));
$pt_year_start = ($pt_month_end != 1) ? $pt_year_end : $pt_year_end-1;
$pt_month_start = ($pt_month_end != 1) ? $pt_month_end-1 : 12;
// How far back should we go?
$tmp_news_id = array();
foreach (explode(',',pt_mod_news_forum_id) as $id)
$tmp_news_id[] = " forum_id='".$id."'";
$query = 'SELECT MIN(posted) FROM '.$db->prefix.'topics WHERE ( '.implode(' OR ', $tmp_news_id).' ) ';
$result = $db->query($query) or fct::error($lang_puntal_mod_news['unable_get_posts'], __FILE__, __LINE__, $db->error());
$pt_history_limit = $db->result($result);
$pt_year_limit = intval(date('Y', $pt_history_limit));
$pt_month_limit = intval(date('n', $pt_history_limit));
$result2 = $db->query('SELECT COUNT(t.id) total, FROM_UNIXTIME(t.posted, "%Y") year, FROM_UNIXTIME(t.posted, "%m") month, FROM_UNIXTIME(t.posted, "%Y-%m") ordre FROM '.$db->prefix.'topics t LEFT JOIN '.$db->prefix.'forums f ON t.forum_id=f.id WHERE ( '.implode(' OR ', $tmp_news_id).' ) AND t.moved_to IS NULL AND t.posted>=UNIX_TIMESTAMP(\''.$pt_year_limit.'-'.$pt_month_limit.'-01\') AND t.posted<UNIX_TIMESTAMP(\''.$pt_year_end.'-'.$pt_month_end.'-01\') GROUP BY year, month ORDER BY ordre DESC') or fct::error('impossible de trouver le nombre de topics par mois', __FILE__, __LINE__, $db->error());
if ($pt_history_limit != null)
{
echo "\t\t\t\t".'<ul>'."\n";
while ($pt_history = $db->fetch_assoc($result2))
{
echo "\t\t\t\t\t".'<li><a href="'.pt_portal_url.'index.php?/news/'.$pt_history['year'].'/'.$pt_history['month'].'">'.$pt_history['year'].'-'.$pt_history['month'].'</a></li>'."\n";
$pt_year_end = $pt_year_start;
$pt_month_end = $pt_month_start;
$pt_year_start = ($pt_month_end != 1) ? $pt_year_end : $pt_year_end-1;
$pt_month_start = ($pt_month_end != 1) ? $pt_month_end-1 : 12;
}
echo "\t\t\t\t".'</ul>'."\n";
}
}Pour la requête, j'ai fait comme ça :
$result2 = $db->query('SELECT COUNT(t.id) total, FROM_UNIXTIME(t.posted, "%Y") year, FROM_UNIXTIME(t.posted, "%m") month, FROM_UNIXTIME(t.posted, "%Y-%m") ordre FROM '.$db->prefix.'topics t LEFT JOIN '.$db->prefix.'forums f ON t.forum_id=f.id WHERE ( '.implode(' OR ', $tmp_news_id).' ) AND t.moved_to IS NULL AND t.posted>=UNIX_TIMESTAMP(\''.$pt_year_limit.'-'.$pt_month_limit.'-01\') AND t.posted<UNIX_TIMESTAMP(\''.$pt_year_end.'-'.$pt_month_end.'-01\') GROUP BY year, month ORDER BY ordre DESC') or fct::error('impossible de trouver le nombre de topics par mois', __FILE__, __LINE__, $db->error());Hors ligne
Pages : 1