Hello. I work on the voting system on the site, there are 3 tables: quiz_quest - questions, quiz_answ - answer choices, quiz_uansw - visitors' answers. Here is the code organized:

 $id = $_GET['quiz']; $answers = mysqli_query($db, "SELECT * FROM quiz_answ WHERE id_quiz_quest = $id"); while ($r_a = mysqli_fetch_array($answers)) { $q_e_d_a = mysqli_query($db, "SELECT *, COUNT(*) AS count_answers FROM quiz_uansw WHERE id_quiz_question=$r_a[id_quiz_quest]"); $rq = mysqli_fetch_array($q_e_d_a); if ($rq['id_quiz_answer'] && $rq['id_quiz_answer'] == $r_a['id']) { $count_answers = $rq['count_answers']; $smarty->assign('count_answers', $count_answers); } else { $smarty->assign('count_answers', '0'); } } 

that is, first the first request is the selection of all from the table of answers for all answers belonging to the question selected in the GET request, and then the request $q_e_d_a - I select the number of people who voted for this answer, and set the condition for showing the number: if this answer though if we chose it once and if it equals the one that is currently used in the $r_a , then we show the number of voters. Otherwise, output 0. The problem is that it outputs 0 in all cases. I mean that it needs to be done by another cycle, but logically I can not figure out how. Give a hint pliz, and I will finalize myself)

  • Maybe in the first condition if you need instead of "$ rq ['id_quiz_answer']" "$ rq ['count_answer']"? - PavelNewSky
  • and mysql at you does not swear on syntax? Generally, values ​​returned from base checked? - PavelNewSky
  • The result is simply displayed as many times as the number of records is displayed by the cycle. I have one voted, so he displays a string with a unit from the database as an array 9 times - user263289
  • Which of the questions did you answer? I don't understand your answer - PavelNewSky
  • On question 2, I fixed the code on the first question, but also unsuccessfully - user263289

0