Create Archive Function


/ Published in: PHP
Save to your folder(s)

This has been updated, fully working now


Copy this code and paste it in your HTML
  1. public function create_archive()
  2. {
  3. // Loop through the database grabbing all the dates::
  4. // $sql = "SELECT DISTINCT blog_date FROM subarc_blog ORDER BY blog_date";
  5. $sql = "SELECT DISTINCT MONTHNAME(blog_date) as blog_month, YEAR(blog_date) as blog_year FROM subarc_blog ORDER BY blog_date";
  6.  
  7. $stmt = $this->conn->prepare($sql);
  8. $stmt->execute();
  9. $stmt->bind_result($month,$year);
  10.  
  11. $rows = array();
  12.  
  13. while($row = $stmt->fetch())
  14. {
  15. $item = array(
  16. 'blog_month' => $month,
  17. 'blog_year' => $year
  18. );
  19. $rows[] = $item;
  20. }
  21. $stmt->close();
  22. return $rows;
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.