我利用 php curl 從 http 撈回 json 數據然後我用 foreach array 來顯示所有數據但遇到一個問題是如何做分頁?對方需要給我怎樣的數據?例如他總共有30筆我要做 10筆一頁。。。
補充
$data = array(
"xxx" => 'xxx'
);
$data_string = json_encode($data);
$ch = curl_init($api);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$result = curl_exec($ch);
curl_close($ch);
$data = json_decode($result);
假設這樣我利用foreach印出所有數據如何做出分頁?
foreach ($data->orders as $order) {
}
- 2 回答
- 0 关注
- 364 浏览
添加回答
举报
0/150
提交
取消