我正在创建一个论坛,我希望最新的帖子格式以粗体或下划线格式化,但我不知道该怎么做。
这是我到目前为止所拥有的
数据库结构;
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>";
};
感谢。
答案 0 :(得分: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>";
};
}
答案 1 :(得分:0)
您可以选择按'posttime'DESC排序的所有主题,然后先选择,或者选择最后一个:
$sql2 = "SELECT * FROM `forum_sub_cats` WHERE `id`='".$row2['id']."' ORDER BY DESC LIMIT 1";
答案 2 :(得分: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