2013-03-24 74 views
0

我有一个会员数据库,可以搜索并返回分页列表的结果。创建下一个/上一个链接基于关闭上一个MySQL搜索

我想要做的/有,是,如果有人点击了搜索结果的该列表的成员的个人资料,该配置文件也可以使用链接到下一个曲线从搜索结果中,或上。

所有此链接需要“动态”包含的是用户标识。例如。

<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”。

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

此外,假设我可以生成一个下/上一链接,访客点击它,如何生成该配置文件的一个/下一个按钮?

我想它的方式是它几乎是次要“寻呼”的脚本,但我不能让我的头周围。谁能帮忙?

回答

0

你可以这样做(伪太代码)

$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 
} 
相关问题