单击“下一步”时,从数组列表中打开随机php页面
我走到了死胡同。我已经做了三个星期了,没有结果 我有10个php页面(单击“下一步”时,从数组列表中打开随机php页面,php,arrays,random,shuffle,Php,Arrays,Random,Shuffle,我走到了死胡同。我已经做了三个星期了,没有结果 我有10个php页面(1.php,2.php,…,10.php)和一个起始页面(start.php) 我所要做的就是将10个页面随机排列,不重复,因此当我在start.php中单击“next”时,它应该转到10个页面中的一个页面(例如,它转到4.php)。当我在4.php中单击“下一步”时,它应该重定向到10页内的另一页,除了4.php 它应该继续这样做,直到所有的数字(1.php-10.php)都显示出来。在这一点上,它应该再次随机化。当我在显示
1.php
,2.php
,…,10.php
)和一个起始页面(start.php
)
我所要做的就是将10个页面随机排列,不重复,因此当我在start.php
中单击“next”时,它应该转到10个页面中的一个页面(例如,它转到4.php
)。当我在4.php
中单击“下一步”时,它应该重定向到10页内的另一页,除了4.php
它应该继续这样做,直到所有的数字(1.php
-10.php
)都显示出来。在这一点上,它应该再次随机化。当我在显示的最后一个数字.php
中单击“下一步”时,它应该将该数字随机化并返回到随机列表中的第一个数字
以下是我目前掌握的情况:
start.php
:
<?php $vidcount = 1; ?>
<? include ("source.php"); ?>
<a href="$nextvid[$vidcount].php">next page</a>
<?php
include ("start.php");
$numbers = range(1, $total_songs);
if(($vidcount == $total_songs)||($vidcount == 1)){
shuffle($numbers);
$vidcount = 1;
}
$nextvid[1] = $numbers[0];
$nextvid[2] = $numbers[1];
$nextvid[3] = $numbers[2];
$nextvid[4] = $numbers[3];
$nextvid[5] = $numbers[4];
$nextvid[6] = $numbers[5];
$nextvid[7] = $numbers[6];
$nextvid[8] = $numbers[7];
$nextvid[9] = $numbers[8];
$nextvid[10] = $numbers[9];
?>
<?php
include("source.php");?>
<?php echo $vidcount; ?>
<a href="testrun[<?php echo $nextvid[$vidcount]; ?>].php">next page</a>
<?php $vidcount++;?>
1.php
,2.php
10.php
:
<?php $vidcount = 1; ?>
<? include ("source.php"); ?>
<a href="$nextvid[$vidcount].php">next page</a>
<?php
include ("start.php");
$numbers = range(1, $total_songs);
if(($vidcount == $total_songs)||($vidcount == 1)){
shuffle($numbers);
$vidcount = 1;
}
$nextvid[1] = $numbers[0];
$nextvid[2] = $numbers[1];
$nextvid[3] = $numbers[2];
$nextvid[4] = $numbers[3];
$nextvid[5] = $numbers[4];
$nextvid[6] = $numbers[5];
$nextvid[7] = $numbers[6];
$nextvid[8] = $numbers[7];
$nextvid[9] = $numbers[8];
$nextvid[10] = $numbers[9];
?>
<?php
include("source.php");?>
<?php echo $vidcount; ?>
<a href="testrun[<?php echo $nextvid[$vidcount]; ?>].php">next page</a>
<?php $vidcount++;?>
1.php
-10.php
具有相同的代码。我还有一个source.php
,用来跟踪显示的数字,并在显示所有数字后重新洗牌
请帮忙。我将非常感激能得到的任何帮助
你不必使用上面的代码,只要我得到的代码有效,如果你有不同的想法,我不介意从头开始。首先,为什么你只有十个文件,而URL中只有一个文件和
?id=X
?但没关系
最好使用会话变量。大概是这样的:
<?php
session_start();
if( !isset($_SESSION['sequence']) || !$_SESSION['sequence']) {
$_SESSION['sequence'] = shuffle(range(1,10));
}
$next = array_shift($_SESSION['sequence']);
// now use $next to create your "Next page" link.
?>
感谢Kolink的回复。我有10个文件,因为这是我获得新页面加载的唯一方法。仅供参考,我不太擅长PHP,我刚开始学习,因为我正在从事一个项目。Kolink,我不太确定如何将您提供的代码合并到我的中。你愿意和我合作吗?我将通过paypal向您发送一份小小的感谢礼物:)这是我的电子邮件solow01(在)gmail.com