【问题标题】:Search form with pagination带分页的搜索表单
【发布时间】:2014-06-16 21:29:27
【问题描述】:

记录结果的分页有问题。

我想使用搜索表单显示保存在 db 表中的所有用户,并根据以下脚本对它们进行分页:

http://papermashup.com/easy-php-pagination/

如果我在下面的查询中手动插入性别值,

"SELECT * FROM $tableName WHERE playerSex  = '0' LIMIT $start, $limit";

显示所有女性用户没问题,

如果我通过这样的表单发送值

"SELECT * FROM $tableName WHERE playerSex  ='" . mysql_real_escape_string($_GET['gendre']) ."' 
LIMIT $start, $limit";

只有第一页显示女性用户。单击第 2 页,脚本会显示所有记录(男性和女性),而不是请求的女性记录。

我该如何解决这个问题?

谢谢

【问题讨论】:

  • 您需要保存或将查询转移到下一页。您的下一页不知道搜索查询是什么。
  • 这是因为您的分页链接不能正常工作。你应该在你的分页href中附加&gender=...
  • 嗨 putvande,如何保存或将查询转移到下一页?

标签: php mysql


【解决方案1】:

您应该将gender 选项保留在您的分页href 中。像这样:

<?php
    foreach $key.... //pagination creator loop
    if(isset($_GET['gender']))
        $href = $key . '&gender=' . $_GET['gender'];
    else
        $href = $key;
?>

【讨论】:

  • 我认为您的意思是 $href 而不是 $herf ;-)
  • 虽然 OP 的“gender”(错误)拼写为“gendre”(实际上这是法语中的性别拼写),但使用的是 $_GET['gendre'],因此不清楚 OP 是否确实拼错了。跨度>
  • @Fred-ii- 抱歉我错了。但代码工作正常
  • 您更改了第一个,但另一个仍显示为 $_GET['gender']&amp;gender - 都必须读取为 gendre
【解决方案2】:

在分页 url 中附加 GET 参数。 例如你有页面网址“http://papermashup.com/easy-php-pagination/”和 分页地址

"http://papermashup.com/easy-php-pagination/?page=1" , 
"http://papermashup.com/easy-php-pagination/?page=2" , 
"http://papermashup.com/easy-php-pagination/?page=3".......

在分页Url中添加GET参数

if($_GET['playerSex'] !="")
{

    $playerSex = "&playerSex=".$_GET['playerSex'];

}

"http://papermashup.com/easy-php-pagination/?page=1$playerSex"
"http://papermashup.com/easy-php-pagination/?page=2$playerSex"
"http://papermashup.com/easy-php-pagination/?page=3$playerSex" .......

【讨论】:

    猜你喜欢
    • 2013-08-29
    • 2019-07-07
    • 1970-01-01
    • 2015-03-14
    • 2019-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多