Welcome Guest, Not a member yet? Register   Sign In
Pagination misses rows! SOLVED!
#1

[eluser]alejandronanez[/eluser]
Hey guys, It's me again... ¬¬

The thing is that my pagination function "misses" the last link, for example.

I got this for my MODEL

Code:
function get_records($num = 0, $offset = 0)
    {
        if($num==0 && $offset==0)
        {
            $query = $this->db->get('AREA_ENSENANZA_NOMBRADO');
            if($query->num_rows()>0)
            {
                foreach ($query->result() as $row):
                    $data['records'][] = $row;
                endforeach;
                $data['total_rows'] = $query->num_rows();
            }else
            {
                $data['total_rows'] = 0;
            }
        }
        else
        {
            $query = $this->db->get('AREA_ENSENANZA_NOMBRADO', $num, $offset);
            if($query->num_rows()>0)
            {
                foreach ($query->result() as $row):
                    $data['records'][] = $row;
                endforeach;
                $data['total_rows'] = $query->num_rows();
            }else
            {
                $data['total_rows'] = 0;
            }
        }
        return $data;
        
    }

And I got this for my CONTROLLER

Code:
function read()
    {
        $query = $this->ar_en_nom_model->get_records();
        if($query['total_rows']>0)
        {
            $this->load->library('pagination');

            $config['base_url'] = 'http://localhost/tesis/index.php/ar_en_nom/index';
            $config['total_rows'] = $query['total_rows'];
            $config['per_page'] = 15;
            $config['num_links'] = 20;
            $config['full_tag_open'] = '<p>';
            $config['full_tag_close'] = '</p>';

            $this->pagination->initialize($config);
            
            $query = $this->ar_en_nom_model->get_records($config['per_page'], $this->uri->segment(3));
            
            $data['records'] = $query['records'];                
        }
                    
        $data['main_content'] = 'ar_en_nom_view';
        $data['template']['titulo'] = 'Area Ense&ntilde;anza Nombrado';
        //$data['template']['controlador'] = 'ar_en_nom';

        $this->load->view('includes/template',$data);
    }

And here's my VIEW

Code:
<h2>&lt;?php echo $titulo; ?&gt;</h2>

&lt;?php echo anchor('ar_en_nom/load_create','Crear Registros') ?&gt;<br /><br />

&lt;?php if($this->session->flashdata('mensaje')) echo $this->session->flashdata('mensaje');
?&gt;
&lt;?php if(isset($records)){;    ?&gt;
    <table border="1" class="tabla">
        <tr>
        <th>Editar</th>
        <th>Borrar</th>
        <th>C&oacute;digo</th>
        <th>Descripcion</th>
        </tr>
    &lt;?php foreach($records as $row): ?&gt;
        <tr>
        <td>&lt;?php echo anchor("ar_en_nom/update/$row->COD_AREA_ENSENANZA_NOMBRADO",'Editar'); ?&gt;</td>
        <td>&lt;?php echo anchor("ar_en_nom/delete/$row->COD_AREA_ENSENANZA_NOMBRADO",'Borrar'); ?&gt;</td>
        
        <td>&lt;?php echo $row->COD_DESCRIPCION; ?&gt;</td>
        <td>&lt;?php echo $row->DESCRIPCION; ?&gt;</td>
        </tr>
    &lt;?php endforeach; ?&gt;
    </table>
&lt;?php echo $this->pagination->create_links();?&gt;
&lt;?php }else{ ?&gt;
<h3>No hay registros de &lt;?php echo $titulo; ?&gt; en la base de datos</h3>
&lt;?php } ?&gt;

The thing is that if I have 30 ROWS, my application loads 14 rows on the pagination 'page' #1 , 15 rows on the pagination #2 and misses the last row. ( it only shows < [1][2] > instead of [1][2][3] ).

I don't know what I'm doing wrong.

Please help me!

Bye guys!!!
#2

[eluser]flaky[/eluser]
may I suggest this little change to the model

Code:
function get_records($num = 10, $offset = 0)
    {
            $query = $this->db->limit($num, $offset)->get('AREA_ENSENANZA_NOMBRADO');
            if($query->num_rows()>0)
            {
                foreach ($query->result() as $row):
                    $data['records'][] = $row;
                endforeach;
                $data['total_rows'] = $query->num_rows();
            }else
            {
                $data['total_rows'] = 0;
            }
    }
#3

[eluser]alejandronanez[/eluser]
I try it man and it doesn't work, I'll check in more detail later, I have to leave, thanks!
#4

[eluser]alejandronanez[/eluser]
I found the solution for that problem...it was so simple that made me laugh xD

Here's the post with the answer!

Solution POST




Theme © iAndrew 2016 - Forum software by © MyBB