CodeIgniter Forums
problem with pagination - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: problem with pagination (/thread-22152.html)



problem with pagination - El Forum - 08-31-2009

[eluser]praveenarya[/eluser]
hi all,
i am having problem with pagination i did as explained in user guide but iam getting errors my code is
Code:
<table width="100%"  border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCFCFD" class="sborder">
                <tr>
                  <td width="5%" nowrap="nowrap" class="menuheading">S.No </td>
                  <td width="65%" height="25" class="menuheading">Loaction</td>
                  <td width="10%" align="center" class="menuheading">Status</td>
                  <td width="10%" align="center" class="menuheading">Edit</td>
                  <td width="10%" align="center" class="menuheading">Delete</td>
                </tr>
                &lt;?
                     $i=0;

                    $query("select * from ab_bus_location where 1  order by loc_id desc");
$total=$query->num_rows();
                    foreach ($query->result_array() as $row)
{                    
                    $i=$i+1;
                    if($row['loc_status']==0) {
                        $fs="In-Active"; $sf=1;$color="red";
                        }else{
                        $fs="Active"; $sf=2;$color="green";
                        }
                  ?&gt;
                <tr bgcolor="#FFFFFF">
                  <td align="center">&lt;? echo $i; ?&gt;.</td>
                  <td height="25" align="left" class="capfont">&lt;? echo $row['loc_name'];?&gt;</td>
                  <td width="10%" align="center"><a href="&lt;? echo base_url();?&gt;index.php/admin/Manage_location/status/&lt;?php echo  $row['loc_id']?&gt;/&lt;&lt;? echo $sf; ?&gt;" class="insub"><font color="&lt;?=$color?&gt;">&lt;?= $fs;?&gt; </font></a></td>
                  <td align="center"><a href="&lt;? echo base_url();?&gt;index.php/admin/Manage_location/edit/&lt;?php echo  $row['loc_id'];?&gt;" class="insub">Edit</a></td>
                  <td width="15%" align="center"><a href="&lt;? echo base_url();?&gt;index.php/admin/Manage_location/delete/&lt;?php echo  $row['loc_id'];?&gt;" class="insub">Delete</a></td>
                </tr>
                &lt;? }  ?&gt;
                <tr bgcolor="#FFFFFF">
                  <td height="25" colspan="5"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td align="center">&lt;?  if($total>0) {
                        $this->load->library('pagination');

$config['base_url'] = current_url();
$config['total_rows'] = $total;
$config['per_page'] = '2';

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

echo $this->pagination->create_links();
                         } else { echo "---- No Records Found ----"; }?&gt;</td>
                      </tr>
                  </table></td>
                </tr>
                
            </table>


i gor error
Severity: Notice

Message: Undefined property: CI_Loader::$pagination

Filename: admin/manage_location.php

Line Number: 125
Fatal error: Call to a member function initialize() on a non-object in D:\wamp\www\example\system\application\views\admin\manage_location.php on line 125


plz help me
thanks in advamce


problem with pagination - El Forum - 08-31-2009

[eluser]n0xie[/eluser]
Move the code to your Controller


problem with pagination - El Forum - 08-31-2009

[eluser]praveenarya[/eluser]
ya i moved but cant see any links i think query should have limit right ,i wrote like
Code:
$qur="select * from ab_bus_location where 1 order by loc_id desc limit $config['uri_segment'],$config['per_page'] ";

please spare me i sound silly , iam new to ci
thanks in advance


problem with pagination - El Forum - 08-31-2009

[eluser]praveenarya[/eluser]
hi all,
my code in controller is
Code:
function index(){
$this->load->library('pagination');
        $config['base_url'] = current_url();
         $fff=$config['uri_segment'] = 4;
        $config['total_rows'] = $this->db->count_all('ab_bus_location');
        $kkk=$config['per_page'] = 3;
           $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
        
        
        $data['results']=$this->db->query("select * from ab_bus_location where 1 order by loc_id desc limit $kkk ");

   $this->load->view('admin/manage_location',$data);

and in view page
Code:
<table width="100%"  border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCFCFD" class="sborder">
                <tr>
                  <td width="5%" nowrap="nowrap" class="menuheading">S.No </td>
                  <td width="65%" height="25" class="menuheading">Loaction</td>
                  <td width="10%" align="center" class="menuheading">Status</td>
                  <td width="10%" align="center" class="menuheading">Edit</td>
                  <td width="10%" align="center" class="menuheading">Delete</td>
                </tr>
                &lt;?  
                     $i=0;
                    
                        foreach ($results->result_array() as $row)
   {
    
                    $i=$i+1;
                    if($row['loc_status']==0) {
                        $fs="In-Active"; $sf=1;$color="red";
                        }else{
                        $fs="Active"; $sf=2;$color="green";
                        }
                  ?&gt;
                <tr bgcolor="#FFFFFF">
                  <td align="center">&lt;? echo $i; ?&gt;.</td>
                  <td height="25" align="left" class="capfont">&lt;? echo $row['loc_name'];?&gt;</td>
                  <td width="10%" align="center"><a href="&lt;? echo base_url();?&gt;index.php/admin/Manage_location/status/&lt;?php echo  $row['loc_id']?&gt;/&lt;? echo $row[" class="insub"><font color="&lt;?=$color?&gt;">&lt;?= $fs;?&gt; </font></a></td>
                  <td align="center"><a href="&lt;? echo base_url();?&gt;index.php/admin/Manage_location/edit/&lt;?php echo  $row['loc_id'];?&gt;" class="insub">Edit</a></td>
                  <td width="15%" align="center"><a href="&lt;? echo base_url();?&gt;index.php/admin/Manage_location/delete/&lt;?php echo  $row['loc_id'];?&gt;" class="insub">Delete</a></td>
                </tr>
                &lt;? }  ?&gt;
                <tr bgcolor="#FFFFFF">
                  <td height="25" colspan="5"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td align="center">&lt;?
                        echo $this->pagination->create_links();
                        ?&gt;</td>
                      </tr>
                  </table></td>
                </tr>
                
            </table>
i cant see any links though it is working fine with limit per page
thanks in advance


problem with pagination - El Forum - 08-31-2009

[eluser]mrcoder[/eluser]
Hi,

change the controler data as

$data['results']=$this->db->query("select * from ab_bus_location where 1 order by loc_id desc limit $fff.$kkk");

i think then its going to work


problem with pagination - El Forum - 08-31-2009

[eluser]praveenarya[/eluser]
thanks for reply i changed as you said,but if i click on pagination links iam getting page not found
thanks


problem with pagination - El Forum - 08-31-2009

[eluser]mrcoder[/eluser]
Hi,

In controler u havent mention

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


place it before data['results'] .


problem with pagination - El Forum - 08-31-2009

[eluser]mrcoder[/eluser]
hi,

Please note the changes in url and echo the query then u can find the correct problem