您好我已经在PHP代码中实现了分页但是在点击分页链接时它没有工作。它显示所有页面的相同数据。这是代码。
控制器:
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
if ([navigationAction.request.URL.relativeString hasPrefix:@"http://click.adzcore.com/"]) {
NSURL *url = navigationAction.request.URL;
[[UIApplication sharedApplication] openURL:url];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
decisionHandler(WKNavigationActionPolicyAllow);
}
型号:
class Testimonial extends CI_Controller {
function __construct() {
parent::__construct();
//here we will autoload the pagination library
$this->load->library('pagination');
}
public function index()
{
$this->load->model('testimonial_model');
$config = array();
$config["base_url"] = base_url('testimonial/index');
$config['total_rows'] = $this->db->count_all("testimonials");//here we will count all the data from the table
$config['per_page'] = 6;//number of data to be shown on single page
$config["uri_segment"] = 2;
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data["records2"] = $this->testimonial_model->get_all_testimonials($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();//create the link for pagination
$data['mainpage'] = "testimonial";
$this->load->view('templates/template',$data);
}
查看:
class Testimonial_model extends CI_Model
{
function get_all_testimonials($limit, $start)
{
$this->db->limit($limit, $start);
$this->db->select('T.*');
$this->db->from('testimonials AS T');
$this->db->where(array('T.status'=>1));
$q = $this->db->get();
if($q->num_rows()>0)
{
return $q->result();
}
else
{
return false;
}
}
}
答案 0 :(得分:2)
尝试以下可能对您有帮助,
public function index()
{
$this->load->model('testimonial_model');
$config = array();
$config["base_url"] = base_url('testimonial/index');
$config['total_rows'] = $this->db->count_all("testimonials");//here we will count all the data from the table
$config['per_page'] = 6;//number of data to be shown on single page
$config["uri_segment"] = 2;
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data["records2"] = $this->testimonial_model->get_all_testimonials($config["per_page"], (($page-1)*$config["per_page"]));
$data["links"] = $this->pagination->create_links();//create the link for pagination
$data['mainpage'] = "testimonial";
$this->load->view('templates/template',$data);
}
答案 1 :(得分:0)
我不能发表评论所以我只是回答这个问题,
下面 http://bootsnipp.com/snippets/featured/rounded-pagination
这是我用来制作我的分页!还有更多的东西!我也使用CI作为我的框架!