Welcome Guest, Not a member yet? Register   Sign In
Another pagination issue
#1

[eluser]gibbo1715[/eluser]
All

Having my first go at the pagination class but doesnt display anything at all on my page

in my controller i have

Code:
private $limit = 3;

function main($offset = 0){
    
$data = $this->global_model->general();
$data['query'] = $this->books_model->books_getall();

$uri_segment = 4;
$offset = $this->uri->segment($uri_segment);
    
$this->load->library('pagination');
$config['base_url'] = 'http://localhost/d/menu/index.php/books/main/';
$config['total_rows'] = $this->books_model->getall();
$config['per_page'] = $this->limit;
$config['uri_segment'] = $uri_segment;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();

$this->load->view('books_main',$data);

And i call it in my view as follows

Code:
<?php echo $pagination; ?>


This seems to mirror what i ve been researching but doesnt return any results

Any ideas

Thanks

Gibbo
#2

[eluser]gibbo1715[/eluser]
Heres my view

Code:
<html>
<head>
<link rel="stylesheet" type="text/css"
      href="<?php echo "$base/$css"?>">
</head>
<body>
<div id="header">
    &lt;? $this->load->view('books_header'); ?&gt;
</div>
<div id="menu">
    &lt;?     $this->load->view('books_menu'); ?&gt;
</div>
    &lt;? echo heading('List of Books',3); ?&gt;
    

&lt;?php echo $pagination; ?&gt;

    
<table border="1">
  <tr>
    <th>ID</th>
    <th>Title</th>    
    <th>Author</th>    
    <th>Year</th>
    <th colspan="2" ALIGN="center">Action</th>        
  </tr>

  
  
  &lt;?php

//Needs to be declared in the global variables
$edit_image = $base;
$edit_image .= 'table-images/edit.png';

$delete_image = $base;
$delete_image .= 'table-images/Thumbs_down.png';

//**********************************************

foreach($query as $row){
  echo "<tr>";
    echo "<td width=4%> Policy:". $row->id ."</td>";
    echo "<td width=50%>". $row->title ."</td>";
    echo "<td width=20%>". $row->author ."</td>";
    echo "<td width=5%>". $row->year ."</td>";
    echo "<td ALIGN=center width=2%>". anchor('books/input/'.$row->id,'<IMG SRC=' .$edit_image .' ALT="Edit Entry"> ') ."</td>";
    echo "<td ALIGN=center width=2%>". anchor('books/del/'.$row->id,'<IMG SRC=' .$delete_image .' ALT="Delete Entry"> ') ."</td>";        
    echo "</tr>";    
}

?&gt;

</table>

<div id="footer">
&lt;? $this->load->view('books_footer'); ?&gt;
</div>

&lt;/body&gt;
&lt;/html&gt;
#3

[eluser]saidai jagan[/eluser]
u printed the number of records in the table.?
#4

[eluser]gibbo1715[/eluser]
i thought id covered everything, how do i print the number of records in the table
#5

[eluser]saidai jagan[/eluser]
echo $config['total_rows'] = $this->books_model->getall();
#6

[eluser]gibbo1715[/eluser]
Doh, ok that was a silly error, wasnt counting in the getall function,

i ve now set that up and the pagination counts properly and returns what i would expect, however,

its not linked into my table though and im not sure why, appologies if im asking daft questions, i am trying to figure this out myself but not getting very far at the moment, my code is still as above

Gibbo
#7

[eluser]gibbo1715[/eluser]
Sorry should have posted the rest of my controller function

Code:
function main($offset = 0){
    
    $data = $this->global_model->general();
    $data['query'] = $this->books_model->books_getall();

// generate pagination
    
        // offset
        $uri_segment = 4;
        $offset = $this->uri->segment($uri_segment);
    
    
        $this->load->library('pagination');
        $config['base_url'] = 'http://localhost/d/menu/index.php/books/main/';
         $config['total_rows'] = $this->books_model->count();
         $config['per_page'] = $this->limit;
        $config['uri_segment'] = $uri_segment;
        $this->pagination->initialize($config);
        $data['pagination'] = $this->pagination->create_links();
    
    
    
$this->load->view('books_main',$data);
#8

[eluser]gibbo1715[/eluser]
OK, getting a bit nearer i think,

in my model i ve changed my get all function to get records as follows

Code:
function get_books($num, $offset) {
    $query = $this->db->get('books', $num, $offset);    
    return $query;


then from my controller i try to call it as follows

Code:
$data['query'] = $this->books_model->get_books($config['per_page'],$this->uri->segment(4));

now i get an error stating

A PHP Error was encountered
Severity: Notice

Message: Trying to get property of non-object

Filename: views/books_main.php

Line Number: 45



any ideas please

Gibbo
#9

[eluser]gibbo1715[/eluser]
Ignore that, got it working, forgot return $query->result(); in my get_books function Smile

Thanks

Gibbo
#10

[eluser]saidai jagan[/eluser]
Code:
function get_books($num, $offset)
{
    $query = $this->db->get('books', $num, $offset);    
    return $query->result_array(); // u shd return the result array
}




Theme © iAndrew 2016 - Forum software by © MyBB