2016-09-20 23 views
0

我有一個大型數據庫,我正在查詢。有多個結果共享相同的「日期」。所以,我今天可能有5個結果,昨天有8個結果,依此類推。單個日期標題下的PHP回顯結果

我重複結果,以便每篇文章現在在標題下面都有「日期」。但是,我正在搜索如何顯示DATE HEADER,然後在分組的每個日期下面顯示文章標題。

SO:

2016年9月19日

  • 第1個標題
  • 第2標題
  • 第3標題
  • 第4標題

2016年9月17日

  • 1_1條標題
  • 2_1條標題
  • 文章標題3_1

...等等。

這是我的MYSQL的快照。感謝先進的NINJAS的super mucho!

enter image description here

代碼如下:

<?php do { ?> 

<b><?php echo date('M. j, Y', ($row_Recordset2['date'])); ?></b><br /> 
<b><a href="/full.php?id=<?php echo $row_Recordset2['id']; ?>"><?php echo stripslashes(htmlspecialchars($row_Recordset2['title'])); ?></a></b><br /> 
<?php echo (stripslashes(str_replace("{nl}", "<br />", $row_Recordset2['short']))); ?> 


<?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?> 
+1

也許是時候展示的代碼? –

+0

添加您的php代碼請 – Farhan

+0

duh,..當我點擊發布時忘了添加它。現在已經開始。哎呦。 – eberswine

回答

1

1)不要使用do..while,只能使用而 2)

<?php $current_date = ''; 
    while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)){ 
     if($current_date !== $row_Recordset2['date']){ 
     echo '<b>' . date('M. j, Y', ($row_Recordset2['date'])) . '</b>'; 
     $current_date = $row_Recordset['date']; 
    } 
     echo "<b><a href=\"/full.php?id=$row_Recordset2[id]\">".  stripslashes(htmlspecialchars($row_Recordset2['title'])) . "</a></b><br />" . 
     (stripslashes(str_replace("{nl}", "<br />", $row_Recordset2['short']))); 
    } 
+0

hmm。不能得到這個工作..不錯,儘管嘗試。 – eberswine

+0

感謝您的編輯。它現在正在工作,沒有錯誤。但是,它仍然顯示多個「相同日期」。是因爲日期需要轉換爲UNIX時間嗎?有關數據庫日期格式,請參閱上面的圖像另外,可能會有迴應的結果,也只有一個日期!謝謝NINJA !! – eberswine