I can not understand why the $colvo_prav
variable $colvo_prav
not increase by 1, but displays a bunch of numbers? That is, it is necessary that for every true
in the if
construct, the $colvo_prav
variable is incremented by one. And if if
false
, then, accordingly, no
for($i = 1; $i <= 25; $i++) { $cookie_t = $_COOKIE["otveti".$i]; $DB->query = "SELECT correct_answer FROM test3 WHERE id=".$i; $correct_answer = $DB->read('correct_answer'); if($cookie_t != '') { $DB->query = "SELECT answer".$cookie_t." as otv FROM test3 WHERE id=".$i; $vash_otv = $DB->read('otv'); } $colvo_prav = 0; if($correct_answer == $vash_otv){ $colvo_prav++; $verno = "Правильно!"; }else $verno = "Неправильно. Правильный ответ:".$correct_answer; $DB->query = "SELECT question FROM test3 WHERE id=".$i; $question = $DB->read('question'); $otveti_na_voprosy = "Вопрос №".$i.": ".$question."\nВаш ответ:".$vash_otv." ".$verno."\n\n"; echo $colvo_prav;
$colvo_prav = 0
must be before the cycle begins - Alexey Shimanskyfor (...
- Alexey Shimanskyecho $colvo_prav
already after the cycle and that's it ..... and this is how (echo) is now called up every iteration inside the cycle ... that's why cadabra adabra is Alexei Shimansky$colvo_prav = 0 должен находится до начала цикла
did you really leave$colvo_prav
also in the cycle? - Alexey Shimansky