Php 论坛结构得到最后的帖子
我的英语不太好。我基本上想显示最后一篇文章在论坛上发布的日期。这是我的论坛shema:Php 论坛结构得到最后的帖子,php,sql,Php,Sql,我的英语不太好。我基本上想显示最后一篇文章在论坛上发布的日期。这是我的论坛shema: `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 `threa
`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 } ?>
$query=mysql\u query(“按论坛顺序从论坛中选择*);
while($row=mysql\u fetch\u assoc($query)){
论坛:
描述:
最后一篇文章:
我如何才能获得所有论坛的最后评论日期?
也许在threads表中添加一个字段,在其中存储最后的评论日期?
也许更好的方法?
我不知道如何更好地解释这个
谢谢您必须查询您的数据库。(您必须在代码中查看这是如何生成的。) (
LIMIT 1
告诉数据库只返回一个条目。)
然后打印该条目。(同样,您必须查看代码。)类似于:
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
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