CI分页,POST方法不起作用

发布于 2024-08-28 18:08:55 字数 1458 浏览 15 评论 0原文

好吧,我对 CI 还很陌生,而且我被困在分页上。我正在对作为查询结果的记录集执行此分页。现在一切似乎都运转良好。但链接可能存在一些问题。我每页显示 10 个结果。现在如果结果小于 10 那就没问题了。或者,如果我提取表中的全部记录,它就可以正常工作。但如果结果超过 10 行,则前 10 行会完美显示,当我单击分页链接进入下一页时,下一页会显示查询的其余结果以及其他结果表中记录。 ???我很困惑..有什么帮助吗?

这是我正在使用的模型代码...

function getTeesLike($field,$param)
{
    $this->db->like($field,$param);
    $this->db->limit(10, $this->uri->segment(3));
    $query=$this->db->get('shirt');
    if($query->num_rows()>0){
        return $query->result_array();
    }
}

function getNumTeesfromQ($field,$param)
{
    $this->db->like($field,$param);
    $query=$this->db->get('shirt');
    return $query->num_rows();
}

这是控制器代码...

$KW=$this->input->post('searchstr');
$this->load->library('pagination');
$config['base_url']='http://localhost/cit/index.php/tees/show/';
$config['total_rows']=$this->T->getNumTeesfromQ('Title',$KW);
$config['per_page']='10';
$this->pagination->initialize($config);
$data['tees']=$this->T->getTeesLike('Title',$KW);
$data['title']='Displaying Tees data';
$data['header']='Tees List';
$data['links']=$this->pagination->create_links();
$this->load->view('tee_res', $data);

我在这里做错了什么???请帮助...

我想问题出在 $KW=$this->input->post('searchstr'); .. 因为如果我硬编码 $KW 的值,它就可以正常工作。也许我应该以不同的方式使用 POST ..但是我如何传递表单中的值而不发布它,它的 CI 所以不是 GET ...??????

Okay, I am pretty new in CI and I am stuck on pagination. I am performing this pagination on a record set that is result of a query. Now everything seems to be working fine. But there's some problem probably with the link. I am displaying 10 results per page. Now if the results are less than 10 then it's fine. Or If I pull up the entire records in the table it works fine. But in case the result is more than 10 rows, then the first 10 is perfectly displayed, and when I click on the pagination link to get to the next page the next page displays the rest of the results from the query as well as, other records in the table. ??? I am confused.. Any help??

Here's the model code I am using ....

function getTeesLike($field,$param)
{
    $this->db->like($field,$param);
    $this->db->limit(10, $this->uri->segment(3));
    $query=$this->db->get('shirt');
    if($query->num_rows()>0){
        return $query->result_array();
    }
}

function getNumTeesfromQ($field,$param)
{
    $this->db->like($field,$param);
    $query=$this->db->get('shirt');
    return $query->num_rows();
}

And here's the controller code ....

$KW=$this->input->post('searchstr');
$this->load->library('pagination');
$config['base_url']='http://localhost/cit/index.php/tees/show/';
$config['total_rows']=$this->T->getNumTeesfromQ('Title',$KW);
$config['per_page']='10';
$this->pagination->initialize($config);
$data['tees']=$this->T->getTeesLike('Title',$KW);
$data['title']='Displaying Tees data';
$data['header']='Tees List';
$data['links']=$this->pagination->create_links();
$this->load->view('tee_res', $data);

What am I doing wrong here ???? Pls help ...

I guess the problem is with the $KW=$this->input->post('searchstr'); ..
Because if I hard code a value for $KW it works fine. May be I should use POST differently ..but how do I pass the value from the form without POSTING it , its CI so not GET ... ??????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅语花开 2024-09-04 18:08:57

控制器

<?php

$KW=$this->input->post('searchstr');
$this->load->library('pagination');

$count = $this->model_name->getNumTeesfromQ($KW);//Count


$config['base_url']= base_url().'index.php/tees/show/';
$config['total_rows']= $count;
$config['per_page']='10';
$config['uri_segment'] = 4;
$limit = $config['per_page'];

$this->pagination->initialize($config);
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$data['links'] = $this->pagination->create_links();


$data['tees']=$this->model_name->getTeesLike($KW,$limit,$page);
$data['title']='Displaying Tees data';
$data['header']='Tees List';

$this->load->view('tee_res', $data);

模型中的

public function getNumTeesfromQ($KW)
{
    $query = $this->db->query("SELECT * FROM title WHERE table_field='$KW'");
    $result = $query->result_array();
    $count = count($result);
    return $count;
}

public function getTeesLike($KW,$limit,$page)
{
    $query = $this->db->query("SELECT * FROM title WHERE table_field='$KW' LIMIT $page, $limit");
    $result = $query->result_array();
    return $result;
}

视图

echo使用foreach

然后在底部页面使用 这将显示您的分页

In Controller

<?php

$KW=$this->input->post('searchstr');
$this->load->library('pagination');

$count = $this->model_name->getNumTeesfromQ($KW);//Count


$config['base_url']= base_url().'index.php/tees/show/';
$config['total_rows']= $count;
$config['per_page']='10';
$config['uri_segment'] = 4;
$limit = $config['per_page'];

$this->pagination->initialize($config);
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$data['links'] = $this->pagination->create_links();


$data['tees']=$this->model_name->getTeesLike($KW,$limit,$page);
$data['title']='Displaying Tees data';
$data['header']='Tees List';

$this->load->view('tee_res', $data);

In Model

public function getNumTeesfromQ($KW)
{
    $query = $this->db->query("SELECT * FROM title WHERE table_field='$KW'");
    $result = $query->result_array();
    $count = count($result);
    return $count;
}

public function getTeesLike($KW,$limit,$page)
{
    $query = $this->db->query("SELECT * FROM title WHERE table_field='$KW' LIMIT $page, $limit");
    $result = $query->result_array();
    return $result;
}

in view

echo all data using foreach

then at bottom of page use <?php echo $links; ?>this will show your Pagination

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文