The first part corresponds to the js code where I call a file that executes the for cycle, but it does not give me the line saturations, putting everything in a column.
<script>
$(document).ready(function() {
$("#nivel-especialidad").change(function() {
$("#nivel-especialidad option:selected").each(function() {
Id = $(this).val();
$.post("../Sql/ArregloRequisitos.php", {Id: Id
}, function(data){
$("#requisitos-nivel").html(data);
});
});
})
});
</script>
In this second part is the HTML code within the For cycle:
<?php
$conexion = new PDO("mysql:host=localhost;dbname=scouts_601_palmira","root","");
$Id_nivel = $_POST['Id'];
echo '<script type="text/javascript">alert("'.$Id_nivel.'");</script>';
$sql3 = "SELECT Id, Texto FROM Requisitos WHERE Id_nivel =".$Id_nivel."";
$sentencia3 = $conexion -> prepare($sql3);
$sentencia3 -> execute();
$requisitos = $sentencia3 -> fetchAll();
echo "<tr>";
for ($i = 0, $contador=1; $i < count($requisitos); $i++, $contador++) {?>
<td>
<div class="card" style="width: 20rem;">
<!--<img class="card-img-top" src="..." alt="Card image cap">-->
<div class="card-body">
<p class="card-text"><?php
echo $requisitos[$i]['Texto'];
?></p>
<input type="checkbox">
</div>
</div>
</td>
<?php if(($contador%3) == 0) {
echo "</tr><tr>";
}
}
echo "</tr>";
?>
Just as this code prints everything in a single column, one div on the other. What I want is that as it says the if condition at the end, is that it shows a div side by side and when three (columns) have already been shown, the line break is done, and this repeatedly until all the data is printed obtained from the BD.
I thank you in advance for any solution to this problem. Currently it looks like this: