分页CI合并表

我需要关于CI分页的帮助。分页CI合并表

以下代码无法正常工作。所有信息都显示在单个页面中,但链接($ this-> pagination-> create_links();)显示正确的页面数量,它应该具有正确的分页。任何时候,我点击下一页或其他页面,它会显示相同的结果。任何建议,使这项工作顺利。谢谢。

public function last_three_months(){ 

$this->load->model('mymodel');

$this->load->database();

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

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

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

$this->load->library("Pagination");

if(date("l",strtotime('now')) == "Monday")

$isMonday = strtotime('now');

else

$isMonday = strtotime('last Monday');

$min = $isMonday - 7257600; // 7257600 = 12 weeks

$max = strtotime('now');

//echo(date("l d M Y",$duration));

$result = $this->mymodel->query('SELECT DISTINCT pi.ID PLAN_ID, pi.IMP_PLAN_DATE DUE_DATE, pi.CHANGE_TICKET CHANGE_TICKET,

pi.PLAN_DESC PLAN_DESC, pi.EC_STAT EC_STAT, per_info.ID PERSON_ID, per_info.FIRSTNAME OWNER_FIRST,per_info.LASTNAME OWNER_LAST,ps.STATUS PLAN_STAT,

pi.TIMESTAMP TIMESTAMP, sn.SN SN, loc.ABBR ABBR, sf.SF SF, pn.ID pn_id, pn.TYPE pn_type, pn.CODE pn_code, pn.YEAR pn_year, pn.NAME pn_name, si.IMP_STAT IMP_STAT

FROM `Plan_Info` pi, `Member` member,`Person_Info` per_info,`Plan_Stat` ps,`Sn_Imp` si,`System_Name` sn,

`Location` loc, System_Family sf, PN pn

WHERE member.MEM_TYPE = "Implementer" AND pi.OWNER = member.PERSON_ID AND member.PERSON_ID = per_info.ID AND pi.PLAN_STAT = ps.ID AND pi.ID = si.PLAN_ID AND si.SN_ID = sn.ID AND sn.LOC_ID = loc.ID AND sn.SF_ID = sf.ID

AND pi.PN_ID = pn.ID AND pi.IMP_PLAN_DATE >= '.$min. ' AND pi.IMP_PLAN_DATE < '.$max.' ORDER BY pi.IMP_PLAN_DATE, loc.ABBR, sf.SF')->result_array();

$plan_info = $this->btree->convertToBtree($result, array('PLAN_ID','DUE_DATE','CHANGE_TICKET','PLAN_DESC','EC_STAT','PERSON_ID','OWNER_FIRST',

'OWNER_LAST','PLAN_STAT','TIMESTAMP','SN','ABBR','SF','pn_id','pn_type','pn_code','pn_year','pn_name','IMP_STAT'), array('PLAN_ID','pn_id','DUE_DATE','ABBR'));

$total = count($plan_info);

$config = array();

$config["base_url"] = base_url() . 'index.php/implementer/last_three_months/';

$config["total_rows"] = $total;

$config["per_page"] = 3;

$config["uri_segment"] = 3;

$config['first_link'] = 'First';

$config['last_link'] = 'Last';

$config['next_link'] = 'next';

$config['prev_link'] = 'prev';

//$config['use_page_numbers'] = TRUE;

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

$link = $this->pagination->create_links();

$content_data = array(

'plan_info' => $plan_info,

'link' => $link

);

$this->load->view('implementer/view_weekly/header');

$this->load->view('logo');

$this->load->view('nev');

$this->load->view('implementer/view_weekly/content',$content_data);

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

}

回答:

首先,你完全搞砸了MVC的设计理念。无论如何,这是一个广泛的话题,这不是你问的问题,所以我会专注于解决你的问题。

public function last_three_months(){ 

$this->load->model('mymodel');

$this->load->database();

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

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

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

$this->load->library("Pagination");

$per_page = 10;

$page = $this->uri->segment(3, 1);

$limit = ($page-1)* $per_page;

if(date("l",strtotime('now')) == "Monday")

$isMonday = strtotime('now');

else

$isMonday = strtotime('last Monday');

$min = $isMonday - 7257600; // 7257600 = 12 weeks

$max = strtotime('now');

//echo(date("l d M Y",$duration));

//Change the following query to COUNT(id) or something like that.

$sql = 'SELECT DISTINCT pi.ID PLAN_ID, pi.IMP_PLAN_DATE DUE_DATE, pi.CHANGE_TICKET CHANGE_TICKET,

pi.PLAN_DESC PLAN_DESC, pi.EC_STAT EC_STAT, per_info.ID PERSON_ID, per_info.FIRSTNAME OWNER_FIRST,per_info.LASTNAME OWNER_LAST,ps.STATUS PLAN_STAT,

pi.TIMESTAMP TIMESTAMP, sn.SN SN, loc.ABBR ABBR, sf.SF SF, pn.ID pn_id, pn.TYPE pn_type, pn.CODE pn_code, pn.YEAR pn_year, pn.NAME pn_name, si.IMP_STAT IMP_STAT

FROM `Plan_Info` pi, `Member` member,`Person_Info` per_info,`Plan_Stat` ps,`Sn_Imp` si,`System_Name` sn,

`Location` loc, System_Family sf, PN pn

WHERE member.MEM_TYPE = "Implementer" AND pi.OWNER = member.PERSON_ID AND member.PERSON_ID = per_info.ID AND pi.PLAN_STAT = ps.ID AND pi.ID = si.PLAN_ID AND si.SN_ID = sn.ID AND sn.LOC_ID = loc.ID AND sn.SF_ID = sf.ID

AND pi.PN_ID = pn.ID AND pi.IMP_PLAN_DATE >= '.$min. ' AND pi.IMP_PLAN_DATE < '.$max.' ORDER BY pi.IMP_PLAN_DATE, loc.ABBR, sf.SF';

$sql2 = 'SELECT DISTINCT pi.ID PLAN_ID, pi.IMP_PLAN_DATE DUE_DATE, pi.CHANGE_TICKET CHANGE_TICKET,

pi.PLAN_DESC PLAN_DESC, pi.EC_STAT EC_STAT, per_info.ID PERSON_ID, per_info.FIRSTNAME OWNER_FIRST,per_info.LASTNAME OWNER_LAST,ps.STATUS PLAN_STAT,

pi.TIMESTAMP TIMESTAMP, sn.SN SN, loc.ABBR ABBR, sf.SF SF, pn.ID pn_id, pn.TYPE pn_type, pn.CODE pn_code, pn.YEAR pn_year, pn.NAME pn_name, si.IMP_STAT IMP_STAT

FROM `Plan_Info` pi, `Member` member,`Person_Info` per_info,`Plan_Stat` ps,`Sn_Imp` si,`System_Name` sn,

`Location` loc, System_Family sf, PN pn

WHERE member.MEM_TYPE = "Implementer" AND pi.OWNER = member.PERSON_ID AND member.PERSON_ID = per_info.ID AND pi.PLAN_STAT = ps.ID AND pi.ID = si.PLAN_ID AND si.SN_ID = sn.ID AND sn.LOC_ID = loc.ID AND sn.SF_ID = sf.ID

AND pi.PN_ID = pn.ID AND pi.IMP_PLAN_DATE >= '.$min. ' AND pi.IMP_PLAN_DATE < '.$max.' ORDER BY pi.IMP_PLAN_DATE, loc.ABBR, sf.SF LIMIT '.$limit.', '.$per_page;

$total = $this->mymodel->query($sql)->num_rows();

$result = $this->mymodel->query($sql2)->result_array();

$plan_info = $this->btree->convertToBtree($result, array('PLAN_ID','DUE_DATE','CHANGE_TICKET','PLAN_DESC','EC_STAT','PERSON_ID','OWNER_FIRST',

'OWNER_LAST','PLAN_STAT','TIMESTAMP','SN','ABBR','SF','pn_id','pn_type','pn_code','pn_year','pn_name','IMP_STAT'), array('PLAN_ID','pn_id','DUE_DATE','ABBR'));

$total = count($plan_info);

$config = array();

$config["base_url"] = base_url() . 'index.php/implementer/last_three_months/';

$config["total_rows"] = $total;

$config["per_page"] = $per_page;

$config["uri_segment"] = 3;

$config['use_page_numbers'] = TRUE;

$config['first_link'] = 'First';

$config['last_link'] = 'Last';

$config['next_link'] = 'next';

$config['prev_link'] = 'prev';

//$config['use_page_numbers'] = TRUE;

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

$link = $this->pagination->create_links();

$content_data = array(

'plan_info' => $plan_info,

'link' => $link

);

$this->load->view('implementer/view_weekly/header');

$this->load->view('logo');

$this->load->view('nev');

$this->load->view('implementer/view_weekly/content',$content_data);

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

}

以上是 分页CI合并表 的全部内容, 来源链接: utcz.com/qa/261912.html

回到顶部