Welcome Guest, Not a member yet? Register   Sign In
count all results pagination problem
#7

[eluser]Ray G[/eluser]
Pursuing CrescendoNZ Idea, I looked into the active record class and added some code to not reset the selection.

Code is located in DB_active_rec.php file starting at line 1008. change the function count_all_results to this
Code:
function count_all_results($table = '', $reset=TRUE)
    {
        if ($table != '')
        {
            $this->_track_aliases($table);
            $this->from($table);
        }

        $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));

        $query = $this->query($sql);
        if($reset === TRUE){
      $this->_reset_select();
    }

        if ($query->num_rows() == 0)
        {
            return 0;
        }

        $row = $query->row();
        return (int) $row->numrows;
    }

now you can count the rows before the limit and offset portion of your query by adding the FALSE parameter to the function.
Example
Code:
$this->db->select(something);
$this->db->from('mytable');
$this->db->where('john', 'doe');
$num_rows = $this->db->count_all_results('', FALSE);
$query = $this->db->get();

I do not consider myself an expert so if someone see's a problem with this or a better way to achieve please post. Always up for constructive criticism. Maybe the powers that be can take this to the next level and include it in the release code since there seems to be a need for it.

Ray


Messages In This Thread
count all results pagination problem - by El Forum - 06-09-2011, 11:46 AM
count all results pagination problem - by El Forum - 06-11-2011, 10:15 PM
count all results pagination problem - by El Forum - 06-12-2011, 02:31 PM
count all results pagination problem - by El Forum - 06-12-2011, 03:03 PM
count all results pagination problem - by El Forum - 06-13-2011, 05:00 AM
count all results pagination problem - by El Forum - 06-13-2011, 04:28 PM
count all results pagination problem - by El Forum - 06-30-2011, 01:38 PM
count all results pagination problem - by El Forum - 06-30-2011, 05:14 PM
count all results pagination problem - by El Forum - 07-08-2011, 01:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB