Hi guys can anyone help me out how to archive by month and year?
and this data came from my database MySql. And if you click that date it will display the content corresponds to that.
Example :
News for 2010
November 10, 2010
October 10, 2010
News for 2009
November 10, 2009
October 10, 2009
Can anyone help me out? How to archive by month and year?
Moderator: General Moderators
-
rolyestemonio
- Forum Newbie
- Posts: 19
- Joined: Fri Jun 18, 2010 10:30 pm
- Location: Metro Manila - Paranaque City
- Contact:
-
rolyestemonio
- Forum Newbie
- Posts: 19
- Joined: Fri Jun 18, 2010 10:30 pm
- Location: Metro Manila - Paranaque City
- Contact:
Re: Can anyone help me out? How to archive by month and year
What is the wrong with this guys? Why is it that when i view the month of November 2010 it also view the month of 2009?Can anyone help me?
This is my display
Code: Select all
<?php include("db.php");
$query = mysql_query("SELECT distinct YEAR(local_date) as year FROM tbl_localnews order by local_date desc");
while($row = mysql_fetch_array($query)) {
//$row = array_unique($r);
$unique_year = $row['year'];
echo($unique_year)."<br>";
$query2 = mysql_query("select distinct monthname(local_date) as month from tbl_localnews where local_date like '$unique_year%' order by local_date desc");
while($r2 = mysql_fetch_array($query2)) {
//$row2 = array_unique($r2);
$unique_month = $r2['month'];
print("<a href='news.php?month=$unique_month'&year=$unique_year>News for $unique_month</a><br>");
//echo($unique_month);
}
}
?>Code: Select all
<?php
$year = $_REQUEST['year'];
$last_date = "";
$result = mysql_query("SELECT *,YEAR(local_date) as year FROM tbl_localnews where year(local_date)='".$year."' ORDER BY local_date DESC ");
//echo '<h1>'.$month.'</h1>';
if(mysql_num_rows($result))
{
while ($row = mysql_fetch_array($result))
{
if ($row['local_date'] != $last_date) {
print("<h2>News for ".date('F j, Y',strtotime($row['local_date']))."</h2>");
$last_date = $row['local_date'];
}
print("<p><b>".$row['local_title']."</b></p>");
print("<p>".$row['local_desc']."</p>");
// print("<p><b>".date('F j, Y',strtotime($row['local_date']))."</b></p>");
//print("<p><b>".$row['local_title']."</b></p>");
//print("<p>".$row['local_desc']."</p>");
}
mysql_free_result($result);
}
?>