Welcome Guest, Not a member yet? Register   Sign In
CI pagination
#1

[eluser]Chilukuri Bhaskar[/eluser]
I am using pagination for displaying records showing in ascending order...
my questions is how to display descending order? any one please help my
#2

[eluser]Grasp Minds[/eluser]
You can add this line for descending order

$this->db->order_by("FIELD_NAME", "desc");
#3

[eluser]Chilukuri Bhaskar[/eluser]
Please find my model code and controller code

Model Code

Code:
function news()
{
   $q = $this->db->query('select * from `news` order by id DESC');
     if($q->num_rows()>0)
  {
  foreach ($q->result_array() as $row)
   {
    $data[] = $row;
   }
   return $data;
  }
  
  
}
and

Controller Code

Code:
function latestnews()
{
  $this->load->model('News_model');
  $this->load->library('pagination');
  
  
  $data['latestNews'] = $this->News_model->news();
  
  $config['base_url']  = 'http://localhost/telugucinemalo/tollywood/latestnews';
  $config['total_rows']  = $this->db->get('news')->num_rows();
  //$config['total_rows']  = $data['latestNews'];
  $config['per_page']  = 10;
  $config['num_links'] = 5;
  
  $this->pagination->initialize($config);  
  $data['latestNews'] = $this->db->get('news', $config['per_page'], $this->uri->segment(3));
  
        $this->load->view('news',$data);
}

please give me solution i need records in descending order

Thanks
Bhaskar
#4

[eluser]Grasp Minds[/eluser]
Refer this

Model
----------
Code:
class news_model extends CI_Model
{
    public function __construct() {
        parent::__construct();
    }

    public function record_count() {
        return $this->db->count_all("news");
    }

    public function fetch_news($limit, $start) {
        $this->db->limit($limit, $start);
  $this->db->order_by("id" , "desc");
        $query = $this->db->get("news");

        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }
}


Controller
----------
Code:
class news extends CI_Controller
{
    public function __construct() {
        parent:: __construct();
        $this->load->helper("url");
        $this->load->model("news_model");
        $this->load->library("pagination");
    }

    public function latestnews() {
        $config = array();
        $config["base_url"] = base_url() . "news/latestnews";
        $config["total_rows"] = $this->news_model->record_count();
        $config["per_page"] = 10;
        $config["uri_segment"] = 5;

        $this->pagination->initialize($config);

        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->news_model->
            fetch_news($config["per_page"], $page);
        $data["links"] = $this->pagination->create_links();

        $this->load->view("latestnews", $data);
    }
}
#5

[eluser]wahmal[/eluser]
how to make it with jquery or ajax so that can run without refresh page??
#6

[eluser]Grasp Minds[/eluser]
Please look this

http://www.graspminds.com/perform-ajax-c...deigniter/




Theme © iAndrew 2016 - Forum software by © MyBB