2013-06-26 50 views
0

我正在創建一個論壇,我想要最新的帖子帖子被格式化爲粗體或下劃線,但我不知道如何做到這一點。格式最近時間

這就是我到目前爲止

DB Structure;

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

此代碼Echo的的發表時間,但我不知道如何充分利用最新的時間進行格式化。

$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>"; 
}; 

感謝。

+1

通過降低posttime並格式化第一行來排序查詢。 –

回答

1

訂單查詢格式化(抱歉忘記了確切的語法)

$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>"; 
    }; 
} 
0

您可以選擇所有的線程由「發表時間」降序排序,然後拿第一,或做最後一:通過郵寄時間降序

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

然後當

$sql2 = "SELECT * FROM `forum_sub_cats` WHERE `id`='".$row2['id']."' ORDER BY DESC LIMIT 1"; 
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