Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8678401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:42:44+00:00 2026-06-12T20:42:44+00:00

In my model I get the entire order table. return $this->db->get(‘order’)->result(); In my view

  • 0

In my model I get the entire order table.

return $this->db->get('order')->result();

In my view i do a foreach to loop through the data.

<?php foreach ($orders as $order) : ?>
<tr>
   <td><?php echo $order->id; ?></td>
   <td><?php echo $order->order_status; ?></td>
   <td><?php echo $order->cart; ?></td>
     . . . 
<?php endforeach; ?>

Ok so that works like a charm. However I need to be able to do some data arranging here.

  1. I want to be able to sort records by id so that I can get the latest on top
  2. I want to split the results (pagination) say every 25 records and add the (go to next page link)

I’m using Codeigniter and building on the MVC pattern. So is their a library perhaps or built-in functions in CI that allow me accomplish these 2 objectives? I appreciate all helpful advice, code examples and general guidance. Thank you in advance for your time! 🙂

Edit 1

Sorry I didn’t mention this.. Can someone give me an example of how the query needs to be structured return $this->db->get('order', 25)->result(); isn’t exactly giving me the desired result here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:42:46+00:00Added an answer on June 12, 2026 at 8:42 pm

    You can use Datatables jquery plugin along with server side implementation , There is already an implementation of datatables wrapper class for code ignitor below is the link for the repository

    It is called Ignited dataTables

    Ignited datatables at github

    You can fork the above repository and try out with your needs

    and also using datatables has another advantage , you can specify server side calls for almost all nice to have functionalities

    such as search in table , pagination , sorting , etc

    EDIT : – After looking at your edit , I found that you are also having problem in fetching data in server side , Here is the codeignitor model function , Put this function in the model class and instantiate and call in your model .

    Pass limit and sort by columns names appropriately

    function getResult($limit, $offset, $sort_by, $sort_order) {
    
            $sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
            $sort_columns = array('id', 'title', 'category', 'rating', 'price');
    
                // set default column name to sortby as per your need 
            $sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by : 'title';
    
            // results query  
                // Change column names as per your need 
    
            $q = $this->db->select('id, title, category,  rating, price')
                ->from('Order')
                ->limit($limit, $offset)
                ->order_by($sort_by, $sort_order);
    
            $ret['rows'] = $q->get()->result();
    
            // count query
            $q = $this->db->select('COUNT(*) as count', FALSE)
                ->from('Order');
    
            $tmp = $q->get()->result();
    
            $ret['num_rows'] = $tmp[0]->count;
    
            return $ret;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public AbstractImagePrototype getIcon(ModelData model) { if (model.get(icon) != null) { return Resources.ICONS.lock(); } else
I'm implementing a custom BCS Model to get data from a backend system. As
I'm using can.Model to retrieve data by id : Invoice = can.Model({ findAll: 'GET
We are trying to get the Model-View-Presenter pattern used on (virtually) all new dev
How can I associate my model class with entire row in JTable in order
NOTE: This is an entire rewrite of the previous question. I have a model.
I was following the instruction to get the entire record from table, and load
EDIT: Here is the entire chunck of what is in the table Hopefully this
I'm wondering is there a difference in terms of computing cost for the Model.get(keys)
How to get model instances of Filter given they should be m2m related to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.