根据以前的MySQL搜索创建下一个/上一个链接


Create Next/Previous links Based Off Previous MySQL Search

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

我想做/拥有的是,如果有人点击搜索结果列表中的成员配置文件,该配置文件也可以使用链接到搜索结果中的下一个配置文件,或到前一个配置文件。

所有这个链接需要'动态'包含的是用户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
}

这就是我的搜索结果。太好了。

所以为了做我想做的,我需要从用户实际点击的行中获得前一行和下一行的'userid'。

示例如果我的结果显示用户id的3,5,12,13,22,41和访问者点击查看用户12(一个新页面),我怎么能抓取5 &用作next/previous?

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

我认为它几乎是一个次要的"分页"脚本,但我无法理解它。有人能帮忙吗?

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

$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
}