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)