0

我正在创建一个论坛,我希望将最新的主题帖子格式化为粗体或下划线,但我不确定如何执行此操作。

这是我到目前为止所拥有的

数据库结构;

id | threadname |   threaddesc   | posttime
 1     thread       description     m-d-y
 2     thread2      description2    m-d-y

此代码回显是 posttime,但我不确定如何格式化最新时间。

$sql2 = "SELECT * FROM `forum_sub_cats` WHERE `id`='".$row2['id']."'";
$res2 = mysql_query($sql2) or die(mysql_error());

while($row3 = mysql_fetch_assoc($res2)){
    echo "  <div class=\"pull-right\"> Latest Thread: ".$row3['posttime']."</div>";
}

用外行的话来说是这样的:

IF($row3['posttime'] > other posttime's) {
    <div class=\"pull-right\"> Latest Thread: <b> ".$row3['posttime']." </b></div>";
} else {    
    <div class=\"pull-right\"> Latest Thread: ".$row3['posttime']." </div>";
};

谢谢。

4

3 回答 3

1

按发布时间降序排列您的查询

$sql2 = "SELECT * FROM `forum_sub_cats` WHERE `id`='".$row2['id']."' ORDER BY posttime DESC

然后在格式化时(抱歉忘记了确切的语法)

$count = 0
while($row3 = mysql_fetch_assoc($res2))
{
    IF($count == 0) 
    {
        echo <div class=\"pull-right\"> Latest Thread: <b> ".$row3['posttime']." </b></div>";
        $count++
    } 
    else 
    {    
        echo <div class=\"pull-right\"> Latest Thread: ".$row3['posttime']." </div>";
    };
}
于 2013-06-26T13:00:14.973 回答
0
    $query = mysql_query("SELECT * FROM forum_sub_cats WHERE id='".$row2['id']."' ORDER BY posttime DESC LIMIT 1");
    $row3 = mysql_fetch_assoc($query)
    echo "<div class=\"pull-right\"> Latest Thread: <b>".$row3['posttime']."<b></div>";

    $query = mysql_query("SELECT * FROM forum_sub_cats WHERE id='".$row2['id']."' ORDER BY posttime DESC LIMIT 50 OFFSET 1");
    while($row3 = mysql_fetch_assoc($query)){
          echo "<div class=\"pull-right\"> Latest Thread: ".$row3['posttime']."</div>";
    }

好吧,我是从头顶写的,但我认为它应该可以工作,如果它不让我知道,我会看看我能做什么。:D

于 2013-06-26T13:02:02.160 回答
0

您可以选择按 'posttime' DESC 排序的所有线程,然后选择第一个或最后一个:

$sql2 = "SELECT * FROM `forum_sub_cats` WHERE `id`='".$row2['id']."' ORDER BY DESC LIMIT 1";
于 2013-06-26T12:55:06.320 回答