Привет, ребята Мне было интересно, можете ли вы помочь мне с увеличением в моем цикле while. Я программирование онлайн викторин с помощью PHP и хочет количество qustion обновлять каждый раз, когда они выбирают кнопку отправки, но переменный $ questionNumber только остается на одинИнкремент В цикле php while
Моего код показан ниже
<?php session_start(); ?>
<html>
<head>
<title> World Cup Quiz </title>
</head>
<body>
<div align = center><strong> World Cup Quiz</strong></div>
<br />
<div align =center>
<?php
include ("dbConnect.php");
$_SESSION['number']=1;
$questionNumber = $_SESSION['number'];
$userScore=0;
$number= rand(1,4);
//search database for generated number and match ID
$dbQuery= "SELECT * FROM `questions 1.0` WHERE `ID` =$number";
$dbResult=mysql_query($dbQuery);
echo "Question:".$questionNumber."/5<br>";
//Assign variables to each attribute
while ($dbRow=mysql_fetch_array($dbResult))
{
$theID=$dbRow["ID"];
$theQuestion=$dbRow["Question"];
$theAnswer1=$dbRow["Correct Answer"];
$theAnswer2=$dbRow["Wrong Answer 1"];
$theAnswer3=$dbRow["Wrong Answer 2"];
$theAnswer4=$dbRow["Wrong Answer 3"];
$_SESSION['number']=$questionNumber+1;
}
//Print Questions and Answers
echo '<strong>'."$theQuestion".'</strong><br>';
?> <form name="correctAnswer" form method="post" action="quiz.php">
<?php
echo "$theAnswer1";?> <input type="radio" name="correctAnswer">
<?php
echo "<br>$theAnswer2"; ?> <input type="radio" name="wrongAnswer1">
<?php
echo "<br>$theAnswer3"; ?> <input type="radio" name="wrongAnswer2">
<?php
echo "<br>$theAnswer4"; ?> <input type="radio" name="wrongAnswer3">
<br><input type="submit" value="Submit Answer">
</form>
</div>
</body>
</html>
Надеется, что вы можете помочь
Благодаря
Works блестяще есть способ, чтобы остановить цикл, если инкрементация попадет определенное число, как 6? – shd0w
@ shd0w Проверьте 'break': http://php.net/manual/en/control-structures.break.php – jeroen