<!DOCTYPE html>
<html>
<head>
<title>Тест</title>
</head>
<body>
<?
$form = $_POST;
function countRows($result2){
$count = $result2->num_rows;
return $count;
}
function getQuestion ($result){
while(($row = $result->fetch_assoc()) != false) {
//echo $row["Ответ"];
return $row["Вопрос"];
}
}
function getAnswer($result){
while(($row = $result->fetch_assoc()) != false) {
//echo $row["Ответ"];
return $row["Ответ"];
}
}
$mysqli = new mysqli ("localhost","root","","Test");
$mysqli->query ("SET NAMES 'utf8'");
$result2 = $mysqli->query ("SELECT * FROM `History`");
countRows($result2);
$randomRow = random_int(1, countRows($result2));
$result = $mysqli->query ("SELECT Вопрос,Ответ FROM `History` WHERE `History`.`id` = $randomRow");
echo getQuestion($result)."<br>";
//echo $form["answer"];
$mysqli->close ();
if($form["answer"] == getAnswer($result)){
echo "Правильно"."<br>";
}else{
echo "Не правльно"."<br>";
}
?>
<form method="post">
<input type="text" name="answer" placeholder="Введите ответ" >
<input type="submit" name="but">
</form>
</body>
</html>