我有http://communitychessclub.com/games-nu.php个游戏分数表。
我希望用户能够从游戏滚动到游戏。游戏按顺序编号,但许多游戏必须删除。
所以我没有“game1001.php”和“game1002.php”,而是“game1203.php”和“game1007.php”。问题是每个游戏都有LR图标,可以向前和向后滚动到其他游戏。 / p>
<?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。
答案 0 :(得分:0)
假设您已定义数组$list
,请将next / prev行更改为:
$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];