Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Dates extends MY_Controller {
- public function index()
- {
- $getMonth = date('m');
- $currentMonth = $getMonth;
- $getYear = date('Y');
- $currentYear = $getYear;
- $firstYear = 2011;
- echo '<h1>' . $currentYear . '</h1><br />';
- for($month = $currentMonth; $month >= 0; $month-- ) {
- if($month < 10) {
- $month = sprintf("%02d", $month);
- }
- if($month == 0 && $currentYear > $firstYear) {
- $month = 12;
- $currentYear--;
- echo '<h1>' . $currentYear . '</h1><br />';
- }
- if($month > 0) {
- $datequery = $currentYear . "-" . $month;
- $this->db->from('px_topics');
- $this->db->like('date', $datequery, 'after');
- $this->db->order_by('date', 'DESC');
- $query = $this->db->get();
- $res = $query->result_array();
- if($query->num_rows() > 0) {
- echo '<h2>' . date("F", mktime(0,0,0, $month, 10)) . '</h2><br />';
- echo '<strong>Your date query is ' . $datequery . '</strong><br />';
- }
- //print_r($res);
- foreach($res as $title) {
- if($query->num_rows() > 0) {
- echo '<h4>Title -' . $title['title'] . '</h4><br />';
- } else {
- echo 'nothing to see here...<br />';
- }
- }
- }
- }
- }
- }
- /* End of file dates.php */
- /* Location: ./application/controllers/dates.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement