![]() |
Pagination problem when search - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Pagination problem when search (/showthread.php?tid=17569) |
Pagination problem when search - El Forum - 04-08-2009 [eluser]truongdd[/eluser] //Controller function search(){ $this->load->library('pagination'); if ($this->input->post('s')) { $this->session->set_userdata('keyword', $this->input->post('s')); } $config['base_url'] = site_url().'kienvang/search/'; $config['total_rows'] = $this->MClassifieds->search_count($this->session->userdata('keyword')); $config['per_page']=5; $config['full_tag_open'] = '<p>'; $config['full_tag_close'] = '</p>'; $this->pagination->initialize($config); //load the model and get results //$this->load->model('mnews'); $data['results'] = $this->MClassifieds->search($config['per_page'],(int) $this->uri->segment(3),$this->session->userdata('keyword')); $data['title'] = "Kien Vang | Search Results"; $data['menulist'] =$this->MCategories->getCategoriesMenu(); $this->load->vars($data); $this->load->view('search'); } ///model function search_count($s){ $data = array(); $this->db->select('id,title,content,created,region'); $this->db->like('title',db_clean($s)); $this->db->orlike('content',db_clean($s)); $this->db->orderby('title','asc'); $this->db->where('status','active'); $Q = $this->db->get('classifieds'); if ($Q->num_rows() > 0){ foreach ($Q->result_array() as $row){ $data[] = $row; } } $Q->free_result(); return $data; } function search($limit,$offset,$s) { $data = array(); $this->db->select('id,title,content,created,region'); $this->db->like('title',$s); $this->db->orlike('content',$s); $this->db->orderby('title','asc'); $this->db->where('status','active'); $Q = $this->db->get('classifieds',$limit,$offset); if ($Q->num_rows() > 0){ foreach ($Q->result_array() as $row){ $data[] = $row; } } $Q->free_result(); return $data; } //view <?php echo "<h3 class='home'>"."Search Results"."</h3>"; echo "<div class='post'>"; if(count($results)){ foreach($results as $key=>$list){ echo "<h3 class='title'>"; echo anchor('kienvang/classified/'.$list['id'],$list['title']); echo "</h3>"; echo "<p class='byline'><small>".$list['created']." | ".$list['region']."</small></p>"; } } echo "</div>"; echo $this->pagination->create_links(); ?> problem: Fatal error: Unsupported operand types in F:\xampp\htdocs\kienvang\system\libraries\Pagination.php on line 112. wish someone for help.Thank! Pagination problem when search - El Forum - 04-08-2009 [eluser]Thorpe Obazee[/eluser] You should post some code so that someone can see the problem and help you. Edit: wow. I look like an idiot asking for some code. Pagination problem when search - El Forum - 04-08-2009 [eluser]Aken[/eluser] Remove the quotes from the number in $config[‘per_page’]=‘5’; By adding quotes you're passing it as a string, where the Pagination script is expecting a numeric integer. That's what the error is saying, basically - "Hey, this isn't a normal integer!" Pagination problem when search - El Forum - 04-09-2009 [eluser]truongdd[/eluser] wish someone for help, to complete the project! Pagination problem when search - El Forum - 04-10-2009 [eluser]Aken[/eluser] I just realized that your model is returning an array of DB query results for your $config['total_rows']. That's definitely not what you want there. You'll want to count those rows, not return them. Pagination problem when search - El Forum - 04-10-2009 [eluser]Aken[/eluser] BTW I want to clarify something - quotes are okay when defining numbers for the total_rows and per_page variables in the pagination library. I was wrong about that. The ceil() and other numeric functions will assume the number is a float type, and work normally. The problem is with your model returning an array, not a number. Pagination problem when search - El Forum - 04-10-2009 [eluser]truongdd[/eluser] thank you!.it work... edit model: function search_count($s){ $this->db->select('id,title,content,created,region'); $this->db->like('title',db_clean($s)); $this->db->orlike('content',db_clean($s)); $this->db->orderby('title','asc'); $this->db->where('status','active'); //$this->db->get('classifieds'); return $this->db->count_all_results('classifieds'); } thank again! |