//一面多少個資料
$results_per_page = 50;
//多少個頁面
$num_pages = ceil(count($friend['data'])/$results_per_page);
//當前頁面
$cur_page = isset($_GET['page']) ? $_GET['page'] : 1;
//定位該頁面的第一筆資料
$skip = (($cur_page - 1 )*$results_per_page);
$friends=array(); //一次只拿50個資料 $friends = array_slice($friend[‘data’],$skip,$results_per_page); //———————————————————— function generate_page_links($cur_page, $num_pages) { $page_links = ”; $before = $cur_page – 4; $after = $cur_page + 4; ($before < 1 ? $before=1:”); ($after > $num_pages ? $after = $num_pages:”); // If this page is not the first page, generate the “previous” link if ($cur_page > 1) { $page_links .= ‘<a href=”‘ . $_SERVER[‘PHP_SELF’] . ‘?page=’ . ($cur_page – 1) . ‘”><-</a> ‘; } else { $page_links .= ‘<- ‘; } // Loop through the pages generating the page number links for ($before; $before <= $after ;$before++) { if ($cur_page == $before) { $page_links .= ‘ ‘ . $before; } else { $page_links .= ‘ <a href=”‘ . $_SERVER[‘PHP_SELF’] . ‘?page=’ . $before . ‘”> ‘ . $before . ‘</a>’; } } // If this page is not the last page, generate the “next” link if ($cur_page < $after) { $page_links .= ‘ <a href=”‘ . $_SERVER[‘PHP_SELF’] . ‘?page=’ . ($cur_page + 1) . ‘”>-></a>’; } else { $page_links .= ‘ ->’; } return $page_links; }