Kód: Vybrať všetko
<?php
$handle = opendir('.');
$conf = 0;
while($dir = readdir($handle))
{
if(substr_count($dir, 'questions_'))
{
$conf++;
}
}
closedir($handle);
$rand = rand(1,$conf);
$file = './questions_'.$rand.'.php';
if(!file_exists($file))
{
die(sprintf('This file: <b>%s</b> doesnt exists. Please create this file.', $file));
}
else
{
include($file);
}
echo '<form method="post" action="results.php?file='.$rand.'">';
for($i = 1; $i <= $numofq; $i++)
{
echo '<b>'.$quest[$i]['otazka'].'</b><br />';
for($y = 1; $y <= $numofval; $y++)
{
echo $quest[$i][$y] . ' <input type="radio" name="q_'.$i.'" value="'.$y.'" /><br />';
}
}
?>
<input type="submit" class="button" value="Submit">
</form>po odoslani vyplneneho testu sa results.php otvaraju na novej stranke:
Kód: Vybrať všetko
<?php
$file = './test_config_'.$_GET['file'].'.php';
if(!file_exists($file))
{
die(sprintf('This file: <b>%s</b> doesnt exists. Please create this file.', $file));
}
else
{
include $file;
}
$correct = 0;
$incorrect = 0;
for($i = 1; $i <= $numofq; $i++)
{
if($_POST['q_'.$i] == $quest[$i]['correct'])
{
$correct++;
}
else
{
$incorrect++;
}
}
print 'Correct Answers: <b>'.$correct.'</b><br />';
print 'Incorrect Answers: <b>'.$incorrect.'</b><br />';
print 'Number of Questions: <b>'.$numofq.'</b><br />';
?>