在 codeigniter 中使用多个搜索标准进行分页

发布于 2024-08-18 07:08:51 字数 1873 浏览 10 评论 0原文

我正在尝试使用多个搜索条件来实现分页。 假设我有学生桌。显示学生列表时我也使用分页。 分页链接是。 site_url 。 '/student/page/'; 所以我使用 $config['uri_segment'] = 1; 所以分页链接将是

<a href="http://mysite/index.php/student/page/0">1</a>
<a href="http://mysite/index.php/student/page/1">2</a>

and son。

之后,我想使用使用文本字段实现的 3 个搜索条件来搜索学生数据。

id  name    address.

用户可以按 ID、姓名、地址或三个条件的组合进行搜索。 url 变成

http://mysite/index.php/student/page/0
href=http://mysite/index.php/student/page/1

和儿子。

但我使用 get 方法进行搜索。当我尝试使用搜索条件字段进行搜索时,

href="http://mysite/index.php/student/page/1?id=1&name=a&address=b

当我尝试根据条件创建分页时,url 就会出现问题。因为分页链接包含查询字符串 我不知道如何创建成为

href="http://mysite/index.php/student/page/0?id=1&name=a&address=b
href="http://mysite/index.php/student/page/1?id=1&name=a&address=b

或者你有解决这个问题的最佳实践吗?


嗨菲尔.... 我已经尝试过你的建议。

$array = array('id' => '001', 'name' => 'a', 'address' => 'canada');

网址变成 id/001/name/a/address/canada。我使用 $this->uri->uri_to_assoc() 函数来获取段的键和值。

array (
    id => 001,
    name=>a,
    address=>canada
)

但是,虽然搜索时未包含一些搜索条件。假设用户仅按姓名和地址进行搜索。数组变成 $array = array('id' => '', 'name' => 'a', 'address' => 'canada'); 和 url id/姓名/地址/加拿大 assoc数组变成

array (
    id => name,
    a=>address,
    canada=>
)

assoc数组不再杂乱无章。所以我无法获得 assoc 数组的正确值。 我想如果不包含的话我会将标识符设置为搜索条件。假设我输入了#

if isset($_GET['id']) then
$id = '#'
else 
$id = $_GET['id']

$array = array('id' => $id, 'name' => 'a', 'address' => 'canada');

怎么样...?或者是否还有其他最佳实践?

Im trying to implement pagination using multiple searching criteria.
Supposed I Have student table. I also use pagination when the list of student displayed.
The pagination link is. site_url . '/student/page/'; so I use $config['uri_segment'] = 1;
so the pagination link will be

<a href="http://mysite/index.php/student/page/0">1</a>
<a href="http://mysite/index.php/student/page/1">2</a>

and son.

After that I wanna search student data using 3 searching criteria implemented using textfield.

id  name    address.

user can search by id or name or address or combination of the three criteria.
the url become

http://mysite/index.php/student/page/0
href=http://mysite/index.php/student/page/1

and son.

but I use get method for searching. and while trying to search using the search criteria field the url become

href="http://mysite/index.php/student/page/1?id=1&name=a&address=b

the problem occurred when I try create pagination based on criteria. because the pagination link have contain query string
i don't know how to create become

href="http://mysite/index.php/student/page/0?id=1&name=a&address=b
href="http://mysite/index.php/student/page/1?id=1&name=a&address=b

or do you have a best practice to solve this problem ?


Hi phill ....
I have try your suggestion.

$array = array('id' => '001', 'name' => 'a', 'address' => 'canada');

the url become
id/001/name/a/address/canada. I use $this->uri->uri_to_assoc() function to get key and value of the segment.

array (
    id => 001,
    name=>a,
    address=>canada
)

but while there some searching criteria that not included while searching. let say, the user only search by name and address. the array become
$array = array('id' => '', 'name' => 'a', 'address' => 'canada'); and the url id/name/a/address/canada
the assoc array become

array (
    id => name,
    a=>address,
    canada=>
)

the assoc array is not disorganized again. so I can't get the right value of the assoc array.
I think i will set the identifier to the searching criteria if not included. supposed i put #.

if isset($_GET['id']) then
$id = '#'
else 
$id = $_GET['id']

$array = array('id' => $id, 'name' => 'a', 'address' => 'canada');

How about that ... ? or if there are another best practice ?

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

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

发布评论

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

评论(2

海拔太高太耀眼 2024-08-25 07:08:51

为此,我将使用 $this->uri->uri_to_assoc():

index.php/user/search/name/joe/location/UK/gender/male

使用此功能您可以将
将 URI 放入关联数组中
这个原型:

[array]
(
    'name' => 'joe'
    'location' => 'UK'
    'gender' => 'male'
)

请参阅此处的完整文档。

您仍然可以使用 page/1 作为第一批,然后使用 /name/whatever。

For that I would use $this->uri->uri_to_assoc():

index.php/user/search/name/joe/location/UK/gender/male

Using this function you can turn the
URI into an associative array with
this prototype:

[array]
(
    'name' => 'joe'
    'location' => 'UK'
    'gender' => 'male'
)

See the full documentation here.

You can still use page/1 as the first lot then have /name/whatever afterwards.

尛丟丟 2024-08-25 07:08:51

实际上,我们可以创建具有多个且无限标准的分页。阅读此处 http://dengkul.com /2010/07/08/codeigniter-pagination-with-multiple-unlimited-searching-criteria/

Actualy, we can create pagination with multiple and unlimited criteria. Read here http://dengkul.com/2010/07/08/codeigniter-pagination-with-multiple-unlimited-searching-criteria/

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