2010-03-19 84 views
1

我創造了我的網站新聞檔案,並希望建立從以下數據表的概述頁面:PHP/MySQL的年月表新聞檔案

id - Unique identifier 
newsDate - in a format XXXX-XX-XX 
title - News Item title 
details - News item 
photo - News Item Photo 
caption - News Item Photo caption 
update - Timestamp for record 

網站上的消息是電流,但我希望能夠在未來幾個月和幾年裏添加一些數據。

我想要做的是爲每年創建一個新行,並突出顯示與DB表中的記錄對應的月份,類似於下面的內容。

2002 JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC 
2004 JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC 
2005 JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC 
2008 JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC 

任何幫助或建議,將不勝感激

+0

像他們的普通新聞報道是爲什麼不將它們導入產生的? – Kevin 2010-03-19 23:05:08

回答

0

棒與你有表格的佈局,然後概述中選擇newsDate的年份和月份和組由(可能與計數,如果你想要顯示每月有多少篇文章),然後遍歷它爲您的線條。應該還算基本做到

0

測試完整的例子

CSS

#Decor 
{ 
    width:200px; 
} 

#Decor, #Decor ul { 
    list-style-type: none; 
    margin-left:25px; 
    margin-bottom:5px; 
    padding-left:20px; 
    cursor:pointer; 
} 

.handle { 
    background: transparent url(/images/tree-handle.png) no-repeat left top; 
    display:block; 
    float:left; 
    width:10px; 
    height:10px; 
    cursor:pointer; 
} 

.closed { background-position: left top; } 
.opened { background-position: left -10px; } 

PHP文件

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <link href="CSS/treeview.css" rel="stylesheet" /> 
    <script src="scripts/jquery-1.11.1.min.js"></script> 
    <script> 
     $(function() { 
      //start the tree in an autocollapsed state 
      $('#Decor ul').hide(400); 

      $('#Decor li').on('click', function (e) { 
       e.stopPropagation(); // prevent links from toggling the nodes 
       $(this).children('ul').slideToggle(); 
      }); 

      // This code opens all hyperlinks in a new window 
      // and avoids anchors 
      $('#Decor a').not('[href="#"]').attr('target', '_blank'); 
     }); 
    </script> 
</head> 

<?php 
define("DB_USER",""); 
define("DB_PASS",""); 
define("DB_HOST",""); 
define("DB_NAME",""); 

$link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die(mysqli_errno()); 
$s="SELECT *,content_id,COUNT(content_id) AS itemCount FROM content_mast GROUP BY DATE_FORMAT(date_upload,'%Y') DESC"; 
$sql_result=mysqli_query($link,$s); 
?> 
<ul id="Decor"> 
<?php 
while($row=mysqli_fetch_array($sql_result)) 
    { 
    $datetime=strtotime($row['date_upload']); 
    $tday = date("Y", $datetime); 
    $count = $row['itemCount']; 
    ?> 
    <li class="level1"><?php echo "<u><strong>{$tday} ({$count})</strong></u><br>"; ?> 
    <?php 
     $s1="select * from content_mast where DATE_FORMAT(date_upload,'%Y')=$tday"; 
     $q=mysqli_query($link,$s1); 
     while($month=mysqli_fetch_row($q)) 
     { 
     ?> 
      <ul> 
       <li><a href="test.php?date=<?php echo $month[5]; ?>"><?php echo date("F",strtotime($month[5])); ?></a></li> 
      </ul> 
      <?php 
     } 
    echo "<br>"; 
    } 
?> 
</ul> 
</html>