【问题标题】:Create Next/Previous links Based Off Previous MySQL Search根据上一个 MySQL 搜索创建下一个/上一个链接
【发布时间】:2013-03-25 02:52:05
【问题描述】:

我有一个可以搜索并返回分页结果列表的会员数据库。

我想要做/拥有的是,如果有人点击搜索结果列表中的成员个人资料,该个人资料还可以使用搜索结果中的下一个个人资料或上一个个人资料的链接。

此链接需要“动态”包含的只是用户 ID。例如。

<p><a href = 'memberprofile.php?$userid'>Previous</a></p>
<p><a href = 'memberprofile.php?$userid'>Next</a></p>

我的结果页的伪代码大致是:

Run query to find number of results which match search criteria
Calculate Number of pages of results and generate page number links
while($row = mysql_fetch_array($result))
{
    //Pull out content from each matching row which match search criteria
}

所以这给了我我的搜索结果。伟大的。

所以为了做我想做的事,我需要从用户实际点击的行中获取前行和下一行的“用户 ID”。

例如,如果我的结果显示用户 ID 为 3、5、12、13、22、41,并且访问者点击查看用户 12(新页面),我如何获取 5 和 13 用作下一个/上一个?

另外,假设我可以生成下一个/上一个链接,并且访问者单击它,我如何为该配置文件生成上一个/下一个按钮?

我的想法是它几乎是一个次要的“分页”脚本,但我无法理解它。有人可以帮忙吗?

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    你可以这样做(也可以使用伪代码)

    $prev_row= NULL;
    $next_row=NULL;
    while($row = mysql_fetch_array($result))
    {
      - this element is the $next_row for previous element, if it is not null, of course
      - the last element is the $prev_row for this element (or default NULL if this one is first)
    
      - Pull out content from each matching row which match search criteria
    
      - store this element so that you can use it in next element as the previous one
    }
    

    【讨论】:

      猜你喜欢
      • 2014-09-26
      • 1970-01-01
      • 2016-12-02
      • 1970-01-01
      • 1970-01-01
      • 2013-01-19
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多