Welcome Guest, Not a member yet? Register   Sign In
MSSQL Pagination Holly Grial?
#21

[eluser]Unknown[/eluser]
this is my controller.
public function test_unique()
{
$id = (isset($_GET['id']) ? $_GET['id'] : '');
$type = (isset($_GET['type']) ? $_GET['type'] : '');
$flag = (isset($_GET['flag']) ? $_GET['flag'] : '');

$this->load->library('Mysession');
$this->load->helper("url");
$this->load->library("pagination");
$this->load->model('adds_model');
$config = array();

$config["base_url"]=.base_url()."?id=".$id."&type;=".$type."&flag;=".$flag;
$config["total_rows"] = $this->adds_model->record_count();
$config["per_page"] = 10;
$config['num_links'] = 10;
$config["uri_segment"] = 3;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';

$this->pagination->initialize($config);

$this->load->view('common/header');
$this->load->view('common/topmenu');
$this->load->view('common/leftmenu');
$this->load->model('adds_model');


$page = ($this->uri->segment( 3)) ? $this->uri->segment(3) : 0;



$data['get_all_impressions'] = $this->adds_model->get_unique_impressions($config["per_page"],$page,$id,$type,$flag);


$this->load->view('adds/testing',$data );

$this->load->view('common/footer');

}


and model is,

//record_count()

public function record_count() {


$query = "SELECT COUNT(*) as count_all FROM impressions where delete_flag = 'N' ";

if ($qh = @odbc_exec($this->conn, $query)Wink
{
while ( $row = @odbc_fetch_object($qh) )
{


$data = $row->count_all;


}
@odbc_free_result($qh);

return $data;

}
else
{
return 0;
}
@odbc_close($this->conn);
}


//get_unique_impressions

function get_unique_impressions($id,$type,$flag)
{
$data = array();

if($type == 'add' && $flag='u')
{


$page = 0;
$limit = ' OFFSET ' . (0 + $page);

$query = "SELECT min(id) as id, min(add_id) as add_id, min(website_id) as website_id, max(page_url) as page_url, max(date_created) as date_created, remote_ip, min(country) as country, min(campaign_id) as campaign_id, count(remote_ip) as cnt from impressions where add_id = '".$id."' group by remote_ip ORDER BY cnt desc ". $limit." ROWS FETCH NEXT 10 ROWS ONLY";

}
elseif($type == 'camp' && $flag='u')
{

//$query = "SELECT * FROM impressions where delete_flag = 'N' and campaign_id = '".$id."' order by id desc ";

$query = "SELECT min(id) as id ,min(add_id) as add_id, min(website_id) as website_id, max(page_url) as page_url, max(date_created) as date_created, remote_ip, min(country) as country, min(campaign_id) as campaign_id, count(remote_ip) as cnt from impressions where campaign_id = '".$id."' group by remote_ip";
}

if ($qh = @odbc_exec($this->conn, $query)Wink
{
while ( $row = @odbc_fetch_object($qh) )
{

$data[] = array("id"=>$row->id,"add_id"=>$row->add_id,"website_id"=>$row->website_id,"page_url"=>$row->page_url,"date_created"=>$row->date_created,"remote_ip"=>$row->remote_ip,"country"=>$row->country,"campaign_id"=>$row->campaign_id,"cnt"=>$row->cnt);

}

@odbc_free_result($qh);



return $data;

}
else
{
return 0;
}
@odbc_close($this->conn);

}


here my problem is ". $limit." ROWS FETCH NEXT 10 ROWS ONLY-> it shows only first 10 rows from database. and also pagination links are doesnot work. then how can i create pagination for mssql server 2012? :-(




Theme © iAndrew 2016 - Forum software by © MyBB