我正在使用 Nestoria API 来检索属性结果。一切运行良好,使用此方法最多可以返回 50 个属性。我想一次显示 10 个项目并允许用户对它们进行分页,但由于某种原因,我很难做到这一点。
控制此部分的代码片段如下:
$page = isset($_REQUEST["page"]) ? (int)$_REQUEST["page"] : 1;
$page = $page-1;
$pagination = new pagination;
$propertyResults = $pagination->generate($nestoria->decodedData->response->listings, 10);
foreach($propertyResults as $listing) {
//do stuff
}
数据数组的片段将是:
Array
(
[0] => stdClass Object
(
[auction_date] =>
[property_type] => house
[summary] => Located in North Kingston a two double bedroom Victorian house presented in...
[title] => York Road, Kingston, KT2 - Reception
[updated_in_days] => 6.5
[updated_in_days_formatted] => this week
)
[1] => stdClass Object
(
[auction_date] =>
[property_type] => house
[summary] => Fine home was built about 50 years ago and enjoys one of the best locations...
[title] => Coombe Hill, KT2 - Conservatory
[updated_in_days] => 2.5
[updated_in_days_formatted] => this week
)
....
(由于数组元素的大小而减少了样本)
现在我已经盯着这个太久了,我已经画了一个空白。
这段代码可以正常工作,除非我尝试转到 1 以外的任何其他页面,然后页面没有完成加载,它只会继续,直到 Firefox 说:“页面没有正确重定向”。
所以基本上,分页能够正确切割我的数据数组,但无法正确“分页”。
有什么帮助吗?