I recently started to use code igniter and was happy it had pagnitation support. However, I need to page a resultset only, not all records.
Below is some code:
First page for search:
Controller:Code:<html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Search string</title> </head> <body> <form method="POST" action="http://localhost/codeigniter/index.php/blog/index"> <blockquote> <blockquote> <p>Search string: <input type="text" name="t1" size="20"> <input type="submit" value="Submit" name="B1"> <input type="reset" value="Reset" name="B2"></p> </blockquote> </blockquote> </form> </body> </html>
View:Code:<?php class Blog extends Controller { function Blog() { parent::Controller(); $this->load->helper('url'); $this->load->helper('html'); } function index() { $this->load->library('pagination'); $t1 = $this->input->post('t1'); $qusql = "SELECT petid, petname, dogpic"; $qusql = $qusql . " FROM pets"; $qusql = $qusql . " WHERE petname Like '".addslashes("$t1%")."'"; $qusql = $qusql . " ORDER BY petname asc"; $query = $this->db->query($qusql); $data['query'] = $this->db->query($qusql); $this->load->view('blog_view', $data); $tra = $query->num_rows(); echo $tra; $config['base_url'] = 'http://localhost/codeigniter/index.php/blog/index'; $config['total_rows'] = $tra; $config['per_page'] = '5'; $this->pagination->initialize($config); echo $this->pagination->create_links(); } } ?>
The line:Code:<html> <body> <table border=1> <tr> <th>pet id</th> <th>pet name</th> <th>dog pic</th> </tr> <?php foreach($query->result() as $row): ?> <tr> <td><?php echo $row->petid ?></td> <td><?php echo $row->petname ?></td> <?php if (empty($row->dogpic)) { echo "<td> </td>"; } else { $tpic = $row->dogpic; // echo "<td><a href=\"http://localhost/codeigniter/upload/$tpic\" target=\"_blank\"><img width=\"80\" border=\"0\" src = \"http://localhost/codeigniter/upload/$tpic\">$tpic</a></td>"; echo "<td><a href=\"http://localhost/codeigniter/upload/$tpic\" target=\"_blank\"><img width=\"80\" border=\"0\" src = \"http://localhost/codeigniter/upload/$tpic\"></a></td>"; } ?> </tr> <?php endforeach; ?> </table> </body> </html>
I tryed in controller and view, all I get is all records displayed. Does anyone know how to page a limited resultset like this. By the way, This code works but no paging.Code:echo $this->pagination->create_links();




Bookmarks