Advertisement
kremisoski

Finally A Prototype I Can Work With...

Aug 4th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Dates extends MY_Controller {
  4.  
  5.     public function index()
  6.     {
  7.         $getMonth = date('m');
  8.         $currentMonth = $getMonth;
  9.         $getYear = date('Y');
  10.         $currentYear = $getYear;
  11.         $firstYear = 2011;
  12.  
  13.         echo '<h1>' . $currentYear . '</h1><br />';
  14.         for($month = $currentMonth; $month >= 0; $month-- ) {
  15.             if($month < 10) {
  16.                 $month = sprintf("%02d", $month);
  17.             }
  18.             if($month == 0 && $currentYear > $firstYear) {
  19.                 $month = 12;
  20.                 $currentYear--;
  21.                 echo '<h1>' . $currentYear . '</h1><br />';
  22.             }
  23.             if($month > 0) {
  24.                 $datequery = $currentYear . "-" . $month;
  25.                 $this->db->from('px_topics');
  26.                 $this->db->like('date', $datequery, 'after');
  27.                 $this->db->order_by('date', 'DESC');
  28.                 $query = $this->db->get();
  29.                 $res = $query->result_array();
  30.                
  31.                 if($query->num_rows() > 0) {
  32.                     echo '<h2>' . date("F", mktime(0,0,0, $month, 10)) . '</h2><br />';            
  33.                     echo '<strong>Your date query is ' . $datequery . '</strong><br />';
  34.                 }
  35.                 //print_r($res);
  36.                 foreach($res as $title) {
  37.                     if($query->num_rows() > 0) {
  38.                         echo '<h4>Title -' . $title['title'] . '</h4><br />';
  39.                     } else {
  40.                         echo 'nothing to see here...<br />';
  41.                     }
  42.                 }
  43.             }
  44.         }
  45.     }
  46. }
  47.  
  48. /* End of file dates.php */
  49. /* Location: ./application/controllers/dates.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement