title: CodeIgniter Pagination Order By Date Results Are Ordered Wrong And Displaying Same Results
body: <p>I'm not sure what I'm doing wrong here.  I've looked all over, but can't find what I'm looking for.  I'm trying to order my results by date.  I'm not sure if it would help to know that the dates are not in order in the table though.  I'm getting similar results on each page instead of loading the next set of records and the dates are out of order.</p>
  
  <pre><code>**Model**
  
  &lt;?php
  
  class Topics_Model extends CI_Model {
  
      public $db_table_name = 'px_topics';
  
      function __construct()
      {
          parent::__construct();
      }
  
      public function record_count()
      {
          return $this-&gt;db-&gt;count_all($this-&gt;db_table_name);
      }
  
      public function fetch_topics($limit, $offset)
      {
          $this-&gt;db-&gt;limit($limit, $offset);
          $this-&gt;db-&gt;order_by("date", "desc");
          $query = $this-&gt;db-&gt;get($this-&gt;db_table_name);
  
          if($query-&gt;num_rows() &gt; 0) {
              foreach($query-&gt;result() as $row) {
                  $data[] = $row;
              }
              return $data;
          }
  
          return FALSE;
      }
  }
  
  **Controller**
  
  &lt;?php
  
  class Test extends MY_Controller {
  
      function __construct()
      {
          parent::__construct();
          $this-&gt;load-&gt;model('user_model');
          $this-&gt;load-&gt;model('topics_model');
          $this-&gt;load-&gt;library('pagination');
      }
  
      function index()
      {
          $data['users'] = $this-&gt;user_model-&gt;get_all();
          $data['sessid'] = $this-&gt;user_model-&gt;get_by_sess_id();
          $data['sessdata'] = $this-&gt;user_model-&gt;get_session_data();
          $data['main_content'] = 'test_view';
          $this-&gt;load-&gt;view('template', $data);
      }
  
      function paged()
      {
          $config = array();
          $config["base_url"] = base_url() . "test/paged";
          $config["total_rows"] = $this-&gt;topics_model-&gt;record_count();
          $config["per_page"] = 5;
          $config["uri_segment"] = 3;
          $config["use_page_numbers"] = TRUE;
          $config["next_tag_open"] = '&lt;div class="next"&gt;';
          $config["next_tag_close"] = '&lt;/div&gt;';
          //$choice = $config["total_rows"] / $config["per_page"];
          //$config["num_links"] = round($choice);
          $config["num_links"] = "3";
  
          $this-&gt;pagination-&gt;initialize($config);
  
          $page = ($this-&gt;uri-&gt;segment(3)) ? $this-&gt;uri-&gt;segment(3) : 0;
          $data["results"] = $this-&gt;topics_model-&gt;fetch_topics($config["per_page"], $page);
          $data["links"] = $this-&gt;pagination-&gt;create_links();
          $data["main_content"] = 'test2_view';
  
          $this-&gt;load-&gt;view('template', $data);
      }
  }
  </code></pre>