Hello,
Im creating a script that would do the following.
There are total 250 ($max) questions, i want the script to randomly pick 50 ($amount) different / unique questions. – This part works!
What i want it to do then is to display 1 ($show) question on each page, then the user would click next, for the next question, or they could go back and retry it.
So what i am having problems with:
1. Only showing the 1 question from the array.2. Only showing the 1 question on the page.
Heres my code:
[code=php]
<?php
$max = 250; $min = 1;
$show = 1; $amount = 50;
$x = 0; $numbers[0] = 0;
$start = isset($_POST[‘s’])?$_POST[‘s’]:0;
$total_rows = isset($_POST[‘t’])?$_POST[‘t’]:”;
$_SERVER[‘PHP_SELF’] = isset($_SERVER[‘PHP_SELF’])?$_SERVER[‘PHP_SELF’]:”;
while (count($numbers) < $amount) {
$ranvar = rand($min, $max);
while(in_array($ranvar, $numbers)) {
$ranvar = rand($min, $max);
}
$numbers[$x] = $ranvar;
$x++;
}
if(!$total_rows)
list($total_rows)=$x;
$startP = $start-$show;
$startN = $start+$show;
$num_pages = intval($total_rows/$show);
if($total_rows%$show)
{
$num_pages++;
}
echo ‘x: ‘.$x.'<br />’;
for($numbers as $value) {
echo ‘Question: ‘.$value.'<br />’;
}
//print_r($numbers);
?>
<table width=”100%”>
<tr>
<td>
<form action=”<?=$_SERVER[‘PHP_SELF’];?>” method=”post”>
<?php
echo $startP>=0? ‘<input type=”submit” value=”PREV”>’.
‘<input type=”hidden” name=”t” value=”‘.$total_rows.'”>’.
‘<input type=”hidden” name=”s” value=”‘.$startP.'”>’:'<input type=”submit” value=”PREV” disabled>’;
?>
</form>
</td>
<td>
<form action=”<?=$_SERVER[‘PHP_SELF’];?>” method=”post”>
<?php
echo $startN<$total_rows? ‘<input type=”submit” value=”NEXT”>’.
‘<input type=”hidden” name=”t” value=”‘.$total_rows.'”>’.
‘<input type=”hidden” name=”s” value=”‘.$startN.'”>’:'<input type=”submit” value=”NEXT” disabled>’;
?>
</form>
</td>
</tr>
</table>
Thanks for any help.