[eluser]1cookie1[/eluser]
[quote author="Gurudutt" date="1263413786"]Hi
I am also new to codeigniter but If you try
$config['query_string_segment'] = 'offset';
$config['page_query_string'] = TRUE;[/quote]
hi Gurudutt
the code above produces a php notice: undefined constant 'query_string_segment' and 'page_query_string'.
One way to get it working is as follows:
forget about the books_model class completely; bin it.
In the 'new' controller:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Books extends Controller
{
function __construct() {
parent::Controller();
$this->load->helper('url');
$this->load->database();
$this->load->library('pagination');
}
function index() {
$data['title'] = 'Books Entries Listing';
$data['result'] = $this->db->get('books','5', $this->uri->segment(3));
//produces SELECT * FROM books LIMIT offset, num rows to return
// SELECT * FROM books LIMIT $this->uri->segment(3), 3
//set pagination parameters
$config['base_url'] = 'http://localhost/CIgniter/books/index/';
$config['total_rows'] = $this->db->count_all('books'); //returns 17
$config['per_page'] = '5';
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
// create pagination links
$data['links'] = $this->pagination->create_links();
//load the view
$this->load->view('books_view', $data);
}
}
/* End of file books.php */
/* Location: ./system/application/controllers/books.php */
and in the 'new' books_view file:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html >
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href='<?php echo base_url(); ?>css/main.css' type="text/css" media="screen, projection" />
<title>CodeIgniter Pagination Tutorial</title>
</head>
<body>
<h1>Book search</h1>
<table>
<?php foreach($result->result_array() as $book): ?>
<tr><td><?php echo $book['bookID'];?></td><td><?php echo $book['aid'] ?></td><td><?php echo $book['title']?></td><td><?php echo $book['company']?></td><td><?php echo $book['typedesc']?></td><td><?php echo $book['isbn']; ?></td>
<?php endforeach; ?>
</table>
<p><?php echo $links; ?></p>
</body>
</html>
It takes away the model->view->controller aspect turning the script into controller->view; which is a little disapointing, but hey, it works a charm over here!
The offset clause in the MySQL query takes a bit of getting used to (fiddling with)!
hope this helps
best wishes :-)