Solved

Show archive DESC from date and add link

Posted on 2012-03-31
3
310 Views
Last Modified: 2012-08-14
I have an archive function working on my Blog using the following code...
mysql_select_db($database_acsinfo, $acsinfo);
 $query_archive = "SELECT YEAR(`eventdate`) AS 'year', MONTH(`eventdate`) AS 'month', COUNT(`id`) AS 'count'  FROM `latestnews` GROUP BY YEAR(`eventdate`), MONTH(`eventdate`) DESC
";
$result = mysql_query($query_archive, $acsinfo) or die(mysql_error());



$data = array();
while($row = mysql_fetch_assoc($result)) {
if( intval($row['count']) >0) $data[$row['year']][$row['month']] = $row['count'];

}

Open in new window



 <?php foreach ($data as $year => $months) {
    echo $year.'';
    foreach ($months as $month => $count) {
            echo date("F", mktime(0,0,0,$month,1,2000)).'('.$count.')<br>';
    }
} ?>

Open in new window


How can I get the dates to show the other way round? ie 2012 first.

Also how would add a link? I need to send a link to the detail page which will show posts from that year & month.
Screen-shot-2012-03-31-at-16.02..png
0
Comment
Question by:BrighteyesDesign
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
OCDan earned 500 total points
Comment Utility
Replace your archive query with this one:
SELECT YEAR(`eventdate`) AS 'year', MONTH(`eventdate`) AS 'month', COUNT(`id`) AS 'count'  FROM `latestnews` GROUP BY YEAR(`eventdate`), MONTH(`eventdate`) ORDER BY YEAR('eventdate') DESC, MONTH('eventdate') DESC
0
 

Author Comment

by:BrighteyesDesign
Comment Utility
That's great, thanks for that.

Where would I add a link around the results so you click on  'July (1)' for example, it takes you a page with the month in the URL to display posts from that month?

I have tried...

           
        <a href="searchrecent.php?month=<?php echo $month ?>" class="sidemenu"> <?php foreach ($data as $year => $months) {
    echo $year.'';
    foreach ($months as $month => $count) {
            echo date("F", mktime(0,0,0,$month,1,2000)).'('.$count.')<br>';
    }
} ?></a>

Open in new window

0
 

Author Comment

by:BrighteyesDesign
Comment Utility
Anyone know how to do this?
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now