如何加载下一个国际象棋游戏页面在php


How to load next chess game page in php

我有一个游戏得分表http://communitychessclub.com/games-nu.php。

我希望用户能够滚动从游戏到游戏。这些游戏是按顺序编号的,但许多游戏必须被删除。

所以不是"game1001.php"answers"game1001.php",我有"game1203.php"answers"game1007.php"的问题是,每个游戏都有L-R图标向前和向后滚动到其他游戏。

<?php $file = $_SERVER["SCRIPT_NAME"]; $game = substr($file,11,4);
$filename = '../games.csv'; if (file_exists($filename)) 
{$last_mod = filemtime($filename);
if (!($games_date == $last_mod)) 
{$games_date = $last_mod; $lines = count(file($filename));}} 
if ($game==1001){$game_prev=1000+$lines;} else {$game_prev = $game-1;}
if ($game==1000+$lines){$game_next=1001;} else {$game_next = $game+1;} 
echo "<div style='"margin:0; padding:0'">"; 
echo "<a href ='"games/game$game_prev"; echo ".php'"> 
<img src='"images/go-back.png'" alt='"next'" class='"atc-L'"></a>";
echo "<a href ='"games/game$game_next"; echo ".php'"> 
<img src='"images/go-next.png'" alt='"next'" class='"atc-R'"></a>";
echo "</div>";
?>

和games.csv是:

1231 
1227 
1223 
1222
1185
1166
1163
1013
1007
1002

我想添加和访问$list

中的元素
$list = array (1231, 1227, 1223, 1222, 1185, 1166, 1163, 1013, 1007, 1002);

我想将这些数字放在数组中并对它们进行排序,然后使用上面的php脚本访问它们。我不介意所有的数字都在一行上,只要php可以对它们进行数组。我如何创建这样一个数组,并让上面的php代码向前和向后滚动,说从game1223.php到game1227.php。

假设您已经定义了数组$list,然后将后面/前面的行更改为:

$index = array_search($game, $list);
$max = count($list)-1;
if ($index == 0) {$index_prev = $max;} else {$index_prev = $index-1;}
if ($index == $max) {$index_next = 0;} else {$index_next = $index+1;}
$game_prev = $list[$index_prev];
$game_next = $list[$index_next];