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 8256251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:48:00+00:00 2026-06-08T01:48:00+00:00

I have a submissions table where users can vote on the content. I’d like

  • 0

I have a submissions table where users can vote on the content. I’d like to add functionality to browse through the submissions in order of votes. I want to limit the number of submissions that appear on each page and implement a pagination system.

So I understand how to use the LIMIT and offset parameters to retrieve rows however this gets the data as it is ordered in the database. I know how to implement pagination in CI. I also know how to ORDER BY the votes column but I’m unsure how to combine the two so that I get the correct output across several pages. Here’s how I’m doing the LIMIT and ORDER BY:

$this->db->limit($count);
$this->db->order_by('votes','desc');
$query = $this->db->get('submission', $num, $offset);

How it should work:

if each page has 10 submissions ordered by votes, the first page should contain the top 10, the second page should contain those submissions with the 11th to the 20th highest votes and so on.

How I’m doing it so far is to simply retrieve all data from the submissions table ordered by votes into an array and then using that as the data source for the pagination. However, this will get rather inefficient as the dataset grows and I would like to know if there is some SQL I’m unaware of that would allow me to only SELECT the appropriate data for each page?

  • 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-08T01:48:03+00:00Added an answer on June 8, 2026 at 1:48 am

    So it looks like I can just construct a query by using ORDER BY followed by the LIMIT and OFFSET for the pagination. I initially tried with a nested select but there’s no need to over-complicate.

    Here’s the PHP code using CodeIgniter’s Active Record class:

    function get_submission_by_vote_pagination($num, $offset)
    {
        $this->db->order_by('votes','desc');
        $query = $this->db->get('submission', $num, $offset);
        return $query->result_array();
    }
    

    With this function it’s easy to use CI’s built in pagination functionality:

     //setup pagination
     $config['base_url'] = base_url() . 'browse/index';
     $config['total_rows'] = $this->Submission_model->count_all();
     $config['per_page'] = '10';
     $config['full_tag_open'] = '<div id="pagination">';
     $config['full_tag_close'] = '</div>';
     $config['first_link'] = 'First';
     $config['last_link'] = 'Last';
     $this->pagination->initialize($config);
    
     $submissions = $this->Submission_model->get_submission_by_vote_pagination(
        $config['per_page'], $this->uri->segment(3));
    
     $this->load->view('browse_page',$submissions);
    

    This does exactly as I wanted without having to get all submissions from the table before sorting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this table where you add taxes. |Name | Rate | Description |
I have a system setup where users can post microposts (basically status updates) and
Suppose that I have an enum column on a table and I want users
I have table with two columns (startdate & enddate) and I have two submission
So, I've got a webapp that lets users submit code. The submissions are stored
I have a PHP page where a user can select a month and then
I'm using cakephp and would like to display all Submissions which are part of
I have an application (http://helios.hud.ac.uk/u0867587/Files/Files.php) If you open the application, click on the Add
i have a table and it display all the record in the table using
I have a forum. I want to perform an SQL query so I can

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.