[eluser]chinedubond[/eluser]
Page Links in pagination behaving funny
Hello the links in my pagination is behaving kinda funny
when the search result page first loads , the pagination links for example shows
<
1,2> so when u go to the next result set by click on the number 2 link
the result set does come up i.e it pulls the correct result set but the produce is instead of the pagination link showing <1,
2> .It is still showing <
1,2> .
so there is no way of navigating to the previous result set .
Thank you.
Code:
This is Model
<?php
class Searchmodel extends Model {
var $thesize=0;
function Searchmodel()
{
// Call the Model constructor
parent::Model();
}
function getSearchResults($keyword,$city,$num, $offset)
{
$qusql = "select companyid, email, companyname, telephone, mobile, address, address2, website, contactpersonid, city, state, logo, featured,keywords";
$qusql = $qusql . " from ng_companies";
$qusql = $qusql . " where city='".addslashes("$city")."'";
$qusql = $qusql . " AND ( companyname like '".addslashes("%$keyword%")."'";
$qusql = $qusql." or keywords like '".addslashes("%$keyword%")."' )";
$firstquery=$this->db->query($qusql);
$this->thesize=count($firstquery->result());
echo 'model '.$offset;
if(empty($offset)){
$offset=0;
echo 'is empty';
}
else{
echo 'is Not empty'.$offset." num: ".$num;
}
$qusql = $qusql." Limit ".addslashes("$offset")." ,";
$qusql = $qusql." ".addslashes("$num")." ";
$query = $this->db->query($qusql);
echo '$query->result() '.count($query->result());
return $query->result();
}
function getSizeofResults(){
return ($this->thesize);
}
<?php
class Searchcontrollers extends Controller {
function Searchcontrollers()
{
parent::Controller();
$rules['keyword'] = "required|min_length[3]";
$rules['locationField'] = "required|min_length[3]";
$this->validation->set_rules($rules);
$fields['keyword'] = 'keyword';
$fields['locationField'] = 'location';
$this->validation->set_fields($fields);
$this->load->library('session');
}
function getResultsByKeyword(){
getListByKeyword($keyword);
}
function validateSearch(){
$this->load->library('validation');
//$this->load->library('indexcontroller');
if ($this->validation->run() == FALSE)
{
$this->setFields();
$this->searchResults();
}
else
{
$this->setFields();
$this->searchResults();
}
}
function searchResults(){
$this->load->model('search/searchmodel', 'searchmodel', TRUE);
$data['title']="Search Results ";
$num=2;
$segment=$this->uri->segment(4);
$keyword=$this->session->userdata('keyword');
$city=$this->session->userdata('city');
$data['searchresults'] = $this->searchmodel->getSearchResults($keyword,$city,$num,$segment);
$config['base_url'] = base_url().'index.php/search/searchcontrollers/searchResults/';
$config['total_rows'] = $this->searchmodel->getSizeofResults();
echo 'total rows '.$config['total_rows'];
$config['per_page'] = '2';
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
$this->load->view('indexsearch',$data);
}
function setFields(){
$keyword = $this->input->post('keyword');
$city = $this->input->post('locationField');
$newdata = array(
'keyword' => $keyword,
'city' => $city);
$this->session->set_userdata($newdata);
}
}
?>