基于辅助字段而不是键的记录集分页。

时间:2013-07-07 14:16:57

标签: php paging recordset

有点坚持如何实现这个......

我有一个PHP页面,显示表格中一条记录的信息。这些记录包括唯一键(image_id)和名称(image_name)。

为了显示正确的记录,我在前一页上使用搜索功能,产生一个URL参数(imageinfo.php?image_id = 1等)。

我的问题是我希望向表中添加前进和后退箭头以循环显示不同的记录,但是基于'image_name'的字母顺序而不是'image_id的数字顺序。

我真的不确定如何实现这一点,所以任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:0)

这样的事情:(我希望评论会解释)

<?php
$data = array(
    123 => "B",
    321 => "C",
    124 => "A"
);
$id = 123; // This is the current image id
asort($data); // Sort the array based on values (names)
// Advance the internal pointer until it points to the current image
while(current($data) != $data[$id])
    next($data);
// TODO: Also check whether next is past end here
echo next($data); // Should be C
相关问题