2009-02-25 8 views
0

Mon anglais n'est pas très bon. Je veux fondamentalement montrer la date à laquelle ce dernier message a été posté dans un forum. Ce forum est mon shema:Forum Structure Obtenir le Dernier Message

`forum_id` int(11) NOT NULL auto_increment 
    `forum_name` varchar(255) NOT NULL 
    `forum_description` text NOT NULL 
    `forum_order` int(11) NOT NULL 

    `thread_id` int(11) NOT NULL auto_increment 
    `thread_title` varchar(255) NOT NULL 
    `thread_text` text NOT NULL 
    `thread_date` datetime NOT NULL 
    `forum_id` int(11) NOT NULL default '0' 
    `thread_author` int(11) NOT NULL 


    `comment_id` int(11) NOT NULL auto_increment 
    `comment_text` text NOT NULL 
    `comment_thread_id` int(11) NOT NULL default '0' 
    `comment_poster` int(11) NOT NULL default '0' 
    `comment_date` datetime NOT NULL 

Forums.php

$query = mysql_query("SELECT * FROM forums ORDER BY forum_order ASC"); 
    while ($row = mysql_fetch_assoc($query)) { 


    <h3>Forum: <?php echo $row['forum_name'] ?><h3> 
    <div>Desc: <?php echo $row['forum_description'] ?></div> 
    <div>Last post: <?php echo $??['comment_date'] ?></div> 
    <?php } ?> 

Comment puis-je faire pour obtenir la dernière date de commentaire pour tous forum? Peut-être ajouter un champ dans la table des discussions où je stocke la date du dernier commentaire? Peut-être un meilleur moyen? Je ne sais pas comment explein ce meilleur.

Merci

Répondre

0

Quelque chose comme:

SELECT forums.*, max(comments.date) as last_comment 
FROM forums 
LEFT OUTER JOIN threads ON forums.forum_id = threads.forum_id 
LEFT OUTER JOIN comments ON threads.thread_id = comments.comment_thread_id 
GROUP BY forums.forum_id 
ORDER BY forum_order ASC 
+0

homme Merci que du bon travail –

0

Vous devez interroger votre base de données. (Vous devez regarder dans votre code comment cela se fait.)

SELECT comment_date FROM dates ORDER BY comment_date DESC LIMIT 1; 

(LIMIT 1 indique la base de données ne retourner une entrée.)

puis imprimez cette entrée. (Encore une fois, vous devez regarder dans votre code.)

Questions connexes