Hi Guys,
Can I ask another question? I am really a beginner in PHP.
I have a problem regarding of archiving. How we are going to archives data by month?
I have 4 fields(id, dates, title,description). I want to archives my data by month in which you can see the Month automatically from database MySQL.
Example
Month retrieved from database
News for November
News for October
News for September
when you click each of this month it will directly open a page archives for each month.
Can anyone help me please. I really confuse how to do it. Thanks for advance guys.
How to archive data by month?
Moderator: General Moderators
-
rolyestemonio
- Forum Newbie
- Posts: 19
- Joined: Fri Jun 18, 2010 10:30 pm
- Location: Metro Manila - Paranaque City
- Contact:
Re: How to archive data by month?
Code: Select all
SELECT * FROM database_name WHERE dates LIKE '2010-11%'-
rolyestemonio
- Forum Newbie
- Posts: 19
- Joined: Fri Jun 18, 2010 10:30 pm
- Location: Metro Manila - Paranaque City
- Contact:
Re: How to archive data by month?
What if i would like to display all months available in my database?
Re: How to archive data by month?
Maybe something like this?
EDIT: Read your original post wrong. Stick the above loop in a form and pass the value of substr($row['dates'], 0, 7) to the page that will display the news.
Code: Select all
$sql = "SELECT dates FROM database ORDER BY dates DESC";
$res = mysql_query($sql);
$current_month = 0;
while ($row = mysql_fetch_array($res))
{
$cm = substr($row['dates'], 5, 2);
if ($cm != $current_month)
{
$current_month = $cm;
echo "<a href=\"somepage.php\">News for " . substr($row['dates'], 0, 7) . "</a><br />";
}
}-
rolyestemonio
- Forum Newbie
- Posts: 19
- Joined: Fri Jun 18, 2010 10:30 pm
- Location: Metro Manila - Paranaque City
- Contact:
Re: How to archive data by month?
Thanks. Your the best. 
Last edited by rolyestemonio on Sun Nov 14, 2010 9:08 pm, edited 1 time in total.
-
rolyestemonio
- Forum Newbie
- Posts: 19
- Joined: Fri Jun 18, 2010 10:30 pm
- Location: Metro Manila - Paranaque City
- Contact:
Re: How to archive data by month?
Thanks you very much. I already solve it. I really appreciate your helps. Happy Merry X-mass.