Posted By

Abe on 01/14/08


Tagged

month count posts order


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Morgano
hochitom
tikitakfire


Posts by month


 / Published in: PHP
 

URL: http://www.ajaxray.com/blog/2007/09/26/how-to-add-archive-functionality-to-your-php-app/

  1. function monthNewsList() {
  2.  
  3. $query = "SELECT COUNT(id) total, MONTHNAME(date) month, YEAR(date) year ";
  4. $query .= "FROM news ";
  5. $query .= "GROUP BY MONTH(date), YEAR(date) ";
  6. $query .= "ORDER BY date ";
  7. $result = mysql_query($query);
  8. $count = mysql_num_rows($result);
  9.  
  10. while ($row = mysql_fetch_assoc($result)) {
  11. echo $row["month"].' '.$row["year"].' ('.$row["total"].")<br />\n";
  12. }
  13.  
  14. }

Report this snippet  

You need to login to post a comment.