Codeigniter - Please suggest me that how to add pagination in this search engine -


--

-- database: ci-intro

create database ci-intro default character set utf8 collate utf8_general_ci; use ci-intro;


--

-- table structure table posts

create table if not exists posts ( id int(11) unsigned not null auto_increment, title varchar(100) default null, body text, created datetime default null, modified datetime default null, primary key (id) ) engine=innodb default charset=utf8 auto_increment=6 ;

--

-- dumping data table posts

insert posts (id, title, body, created, modified) values (1, 'another day still looking', 'my lion ran off', '2013-04-02 08:20:20', '2013-04-03 12:43:49'), (2, 'a day', 'the lion in 1 piece.', '2013-04-02 08:20:44', '2013-04-02 08:20:44'), (3, 'thank god', 'everything belongs father', '2013-04-02 08:21:03', '2013-04-02 08:21:03'), (4, 'at seaside', 'we went down sea side, started raining!', '2013-04-02 08:21:35', '2013-04-03 19:28:48'), (5, 'boring posts', 'the events diary not interesting', '2013-04-02 08:21:55', '2013-04-03 19:35:25');


application\controllers\posts.php

function search() {     $data['title'] = "blogging";     $data['heading'] = "bloging";      $this->load->view('view_search', $data); } 

application\views\view_search.php

    <?php echo form_fieldset('<b>search post!</b>');?>      <?php echo form_open('posts/execute_search'); ?>     <table width="100%" border="0" align="center" cellpadding="0" cellspacing="5" style="border:dashed"  bgcolor="#ffcc99">         <tr>             <td align="right">                 <?php echo form_label('search: enter keyword, title, content '); ?>             </td>             <td>                  <?php  echo form_input(array('name'=>'search')); ?>             </td>         </tr>         <tr>             <td align="right" valign="top"><?php echo nbs(1); ?></td>             <td valign="top" class="style1"><?php echo form_submit('search_submit','submit'); ?></td>         </tr>      </table>     <?php echo form_close(); ?>     <?php echo form_fieldset_close(); ?> 

application\controllers\posts.php

public function execute_search($search_term) {     $data['title'] = "blogging";     $data['heading'] = "bloging";       $search_term = $_post['search'];      $rs = $this->db->like('title', trim($search_term))             ->or_like('body', trim($search_term))             ->get('posts');     $total = $rs->num_rows();      $data['results'] = $rs->result();      $this->load->view("view_index", $data);  } 

to use pagination.. need use pagination class library of codeigniter ... load library

 $this->load->library('pagination'); 

and call function in controller

 $config['base_url'] = 'http://example.com/index.php/test/page/';  $config['total_rows'] = 200;  $config['per_page'] = 20;    $this->pagination->initialize($config);  

and print create_lnks want pagination stay...(view)..

  echo $this->pagination->create_links(); 

you can go through docs here... read more pagination class.. , customization


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -