I have a panel survey manager where I add, edit and delete dimensions and questions of the survey, through this the survey that contains 4 dimensions, in a total of 21 questions and with a likert scale, is applied.
My problem is based on placing a counter so that the name
of each radio button
is different I will attach an example:
The question 1
name="likert1"
, the question 2name="likert2"
and so on Question 21name="likert 21"
.
I enclose the code where I make the consultations
<?php
require 'conexion.php';
mysqli_query($mysqli,"SET NAMES 'utf8'");
?>
<html lang="es">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.css" rel="stylesheet">
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<h2 style="text-align:center">Encuesta estudiantes</h2>
<br>
</div>
<?php
$sql = "SELECT * FROM dimension";
$resultado = $mysqli->query($sql);
foreach($resultado as $row){
?>
<div class="row table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>
<?php echo $row['nombre_dimension']; ?>
</th>
<th width="10%">No aplica</th>
<th width="10%">Muy en desacuerdo</th>
<th width="10%">En desacuerdo</th>
<th width="10%">En acuerdo</th>
<th width="10%">Muy en desacuerdo</th>
</tr>
</thead>
<tbody>
<?php
$sqlP = "SELECT * FROM preguntas WHERE id_dimension_p=".$row['id_dimension'];
$resultadoP = $mysqli->query($sqlP) or die (mysqli_error());
foreach($resultadoP as $row){
$likert=0;
?>
<tr>
<td>
<?php echo $row['nombre']; ?>
</td>
<td>
<center><input type="radio" name='<?php echo $likert; ?>' value="no aplica"></center>
</td>
<td>
<center><input type="radio" name='<?php echo $likert; ?>' value="muy en desacuerdo"></center>
</td>
<td>
<center><input type="radio" name='<?php echo $likert; ?>' value="en desacuerdo"></center>
</td>
<td>
<center><input type="radio" name='<?php echo $likert; ?>' value="en acuerdo"></center>
</td>
<td>
<center><input type="radio" name='<?php echo $likert; ?>' value="muy en desacuerdo"></center>
</td>
</tr>
<?php }
$likert++;
}?>
</tbody>
</table>
</div>
</div>
</body>
</html>
I await your guidance or help, thank you very much