Survey for students of a school to evaluate their teachers

2

I have a code with which I intend to make a teaching evaluation. I need users to be able to select only one rating for each name and not several as in the following example with "juan hernandez".

This is the code I have

 <table class="table table-bordered">
 <tr>
   <th>Docente</th>
   <th>1</th>
   <th>2</th>
   <th>3</th>
   <th>4</th>
   <th>5</th>
 </tr>
 <tr>';
// $mostrando_docentes=mysqli_fetch_array($mostrar_maestros);
 while ($mostrando_docentes=mysqli_fetch_array($mostrar_maestros)) {
   echo '<td>'.$mostrando_docentes['Nombre']." ".$mostrando_docentes['ApellidoP']." ".$mostrando_docentes['ApellidoM'].'</td>       

   <td><input type="radio" name="respuesta"  ></td>


   <td><input type="radio" name="respuesta1" ></td> 

   <td><input type="radio" name="respuesta2" ></td>

   <td><input type="radio" name="respuesta3" ></td>

   <td><input type="radio" name="respuesta4" ></td>

 </tr>

 ';}echo'  

    
asked by uzziel sánchez díaz 02.08.2017 в 23:10
source

4 answers

3

The problem you have is that each radio button the name they have is different in the same teacher so you can select several, to correct this, in the line to get the teachers $mostrando_docentes=mysqli_fetch_array($mostrar_maestros); you could get the ID of each teacher and call the radio buttons with that id, so that for each teacher is different, in code would be something like this:

<?php
$mostrando_docentes=mysqli_fetch_array($mostrar_maestros);
while ($mostrando_docentes=mysqli_fetch_array($mostrar_maestros)) {
   echo '<tr><td>'.$mostrando_docentes['Nombre']." ".$mostrando_docentes['ApellidoP']." ".$mostrando_docentes['ApellidoM'].'</td>';?>       

   <td><input type="radio" name="docente_<?php echo $mostrando_docentes['idDocente'];?>"  ></td>


   <td><input type="radio" name="docente_<?php echo $mostrando_docentes['idDocente'];?>" ></td> 

   <td><input type="radio" name="docente_<?php echo $mostrando_docentes['idDocente'];?>" ></td>

   <td><input type="radio" name="docente_<?php echo $mostrando_docentes['idDocente'];?>" ></td>

   <td><input type="radio" name="docente_<?php echo $mostrando_docentes['idDocente'];?>" ></td>

 </tr>
<?php } ?>
    
answered by 02.08.2017 / 23:35
source
2

You have to create a set of radios for each answer, all with the same name and their respective value, because that's how it works, example:

<td><input type="radio" name="respuesta" value="1"></td>
<td><input type="radio" name="respuesta" value="2"></td>
<td><input type="radio" name="respuesta" value="3"></td>
<td><input type="radio" name="respuesta" value="4"></td>
<td><input type="radio" name="respuesta" value="5"></td>

So you can only select one option on each line. The problem is that you can not repeat the name for the other teachers, you will have to do something like:

<?php
// Supongamos que ya asignaste id de docenta a la variabla $id
for($i = 1; $i <= 5; $i++) {
    echo "<td><input type=\"radio\" name=\"respuesta-$id\" value=\"$i\"></td>\n";
}

With that you will have a set of radios for each teacher and only one option can be selected. To know how to handle them when processing the form use var_dump ($ _ POST); and there you will see the answers.

    
answered by 02.08.2017 в 23:38
1

The problem is in your radio buttons, the radio buttons must define the same name and add their respective value:

  <tr>  
   <td><input type="radio" name="respuesta" value ="respuesta1" ></td>     
   <td><input type="radio" name="respuesta" value ="respuesta2" ></td>    
   <td><input type="radio" name="respuesta" value ="respuesta3" ></td>    
   <td><input type="radio" name="respuesta" value ="respuesta4" ></td>
  </tr>

  <tr>   
   <td><input type="radio" name="respuesta1" value ="respuesta1" ></td>     
   <td><input type="radio" name="respuesta1" value ="respuesta2" ></td>    
   <td><input type="radio" name="respuesta1" value ="respuesta3" ></td>    
   <td><input type="radio" name="respuesta1" value ="respuesta4" ></td>
 </tr>

If the answer solves your problem, do not forget to leave your vote and indicate if it was useful.

    
answered by 02.08.2017 в 23:34
0

Checking your code I see that you keep different names, when using radio input, these are grouped by names, that is, they can only be selected among those that maintain the same name (name).

An example:

<form> <p>Check the languages you are most proficient in.</p> <input type="radio" name="chooseone" value="HTML"><label for="HTML"> HTML</label><br> <input type="radio" name="chooseone" value="CSS"><label for="CSS"> CSS</label><br> <input type="radio" name="chooseone" value="JS"><label for="JS"> JS</label><br> <input type="radio" name="chooseone" value="PHP"><label for="PHP"> PHP</label><br> <input type="radio" name="chooseone" value="Ruby"><label for="Ruby"> Ruby</label><br> <input type="radio" name="chooseone" value="INTERCAL"><label for="INTERCAL"> INTERCAL</label><br> </form>
    
answered by 02.08.2017 в 23:34