3
Hello, good(a) day, afternoon or night, I would like you to help me answer what I am doing wrong in my code, because, I have already tried to redo and do everything and more, and I am not understanding, I will explain by steps:
1 Well, I created a system of select questions, but before I select the question itself, I have to select the gender of it, because it is in the bank, answering questions and product questions.
[Select HTML & PHP code]
<div class="card" style="width: 75rem; height: 31rem; margin-top: 1rem; margin-left: 1px;">
<div class="card-header">
<h2 align="center">Painel Administrativo - Selecione as Perguntas:</b> </h2>
</div>
<div class="card-body">
<!-- Passa as perguntas via metodo POST mas não as salva no user_tb -->
<form action="cliente.php" method="POST">
<h6>Selecione o genero das perguntas: </h6>
<!-- Script de puxar os generos selecionados -->
<script type="text/javascript">
$(function() {
$('#selecionar').change(function(){
$('.perguntas').hide();
$('#' + $(this).val()).show();
});
});
</script>
<!-- Select com as opções de generos -->
<select id="selecionar" class="col-sm-12">
<option value="0">...</option>
<option value="atendimento">Atendimento</option>
<option value="produto">Produto</option>
</select>
<!-- Opção 1 = Atendimento -->
<div id="atendimento" class="perguntas" style="display: none;">
<br><b>Selecione as perguntas:</b></br><br>
<?php
// seleciona na tabela perguntas_tb somente o genero de atendimento
$sqlselecionargenero = "SELECT * FROM perguntas_tb WHERE genero = 'Atendimento' ";
// prepara o genero de atendimento a ser executado
$preparargenero = $conn->prepare($sqlselecionargenero);
$preparargenero -> execute();
// cria apartir da preparação de puxar os generos do banco de dados, uma variavel chamada pa
// PA = Pergunta de Atendimento
// cada pergunta tem que ter seu propio valor para ser atribuido a ela 5 checkbox
// how to do?
foreach ($preparargenero as $pa) {
$id = $pa["id"];
$perguntas = $pa["perguntas"];
echo "<p><input type='checkbox' name='atendimento[]' value='$perguntas' id='' name='atendimento' >"." ".$perguntas;
}
?>
<p><button type="submit">Salvar perguntas</button></p>
</div>
<!-- Opção 2 = Produto -->
<div id="produto" class="perguntas" style="display: none;">
<!-- AINDA FALTA FAZER A PARTE DE PRODUTO, ESTOU PRIMEIRO FAZENDO A PARTE DE ATENDIMENTO -->
</div>
</form>
</div>
</div>
It generates from the amount of questions with kind of Attendance at the bank, ie it pulls all the questions, so far so good...
2 After I select the genre, and choose the questions and click on save i pass via post method, the questions I selected for a client.php page, and this page would be like a form, where apart from the questions I passed I assign 5’s exclusive checkbox for each question, and from these checkboxes I would like to assign values to them, and send such values to the database so that I can create a graph. But then I can’t develop anything else, how do I separate the questions by paging? I wouldn’t want them all to be on the same page, for example, I would like to use a bootstrap feature to go back and forth, to answer the questions, and not to answer them all in a single div, could someone help me?
<div style="margin-left: 1rem; margin-top: 1rem;">
<form method="POST">
<?php
// Verifica se alguma pergunta foi selecionada
if(isset($_POST["atendimento"])) {
// Faz um loop no Array de checkbox
// A função count retorna a quantidade de checkbox selecionado
for($i = 0; $i < count($_POST["atendimento"]); $i++) {
echo $_POST['atendimento'][$i]."<br />";
echo "<p>";
echo "<input type='radio' name='$i'> Muito Satisfeito ";
echo "<input type='radio' name='$i'> Satisfeito ";
echo "<input type='radio' name='$i'> Pouco Satisfeito ";
echo "<input type='radio' name='$i'> Insatisfeito ";
echo "<input type='radio' name='$i'> Muito Insatisfeito ";
echo "<p><br>";
}
}
?>
<p><button type='submit'>Enviar</button></p>
</form>
</div>
I’d be grateful if you could help me!!
echo "<input type='radio' name='$i'> Muito Satisfeito ";
when you do so because you do not add avalue="XXX"
– Pbras
Yes, this is what I have already done, to assign value, just like each question, has to have a different answer, the values will be duplicated from cb above and below, IE, at the time of making the graph, there will be no way to separate oq is oq
– Gustavo Bertoi
In each metes value="Very Satisfied" or value="Satisfied" each one gets a different value depending on the radio check the user gave.
– Pbras