初始化會話陣列
$_SESSION['theValue'] = $result_array;
$_SESSION['currentIndex'] = 0;
創建按鈕下一首/上這樣
$prev = $_SESSION['currentIndex'] == 0 ? 0 : $_SESSION['currentIndex'] - 1;
$next = $_SESSION['currentIndex'] == sizeof($_SESSION['theValue']) ? $_SESSION['currentIndex'] : $_SESSION['currentIndex'] + 1;
,並要去一個/上一個頁面,只需增加/減少$_SESSION['currentIndex']
用例:
所以當你創建鏈接如下:
<a href="index.php?page=1">Next</a>
<a href="index.php?page=0">Prev</a>
你需要捕捉的$_GET['page']
值,並將其保存渲染內容之前CURRENTINDEX會話屬性。
if(isset($_GET['page'])){
if(is_numeric($_GET['page']){
if($_GET['page'] >= 0 && $_GET['page'] <= sizeof($_SESSION['theValue'])){
$_SESSION['currentIndex'] = $_GET['page'];
}
}
}
// place code which works with 'currentIndex' and array in session here...
*將陣列一次移動一步*這行代表什麼意思? –