2
I have 1 table with 1 list of modules, and I have 2 columns that have options that can be chosen through select.
The point is that the select’s only load the data in the first row of the table, the next comes out blank, I think it’s the way I’m using my loops that might be wrong.
Below is the code of my table:
<?php
echo" <div class='table-responsive'>
<table class='table lista-clientes table-striped table-hover table-bordered table-condensed'>
<thead>
<tr>
<th>SISTEMA</th>
<th>STATUS</th>
<th>NIVEL</th>
<th align='center'>
SALVAR
</th>
</tr>
</thead>
<tbody>";
while($rowModulosSistemas = mysqli_fetch_assoc($resultModulosSistemas)) {
echo"
<tr>
<td>".$rowModulosSistemas["mod_sist_titulo"]."</td>
<td>
<select class='form-control' id='status' name='status'>
<option></option>";
while($rowStatus = mysqli_fetch_assoc($resultStatus)) {
echo"<option value='".$rowStatus["STATUS"]."'>".$rowStatus["DESCRICAO"]."</option>";
}
echo"
</select>
</td>
<td >
<select class='form-control' id='nivel' name='nivel'>
<option></option>";
while($rowNivelUsuarios = mysqli_fetch_assoc($resultNivelUsuarios)) {
echo"<option value='".$rowNivelUsuarios["ID"]."'>".$rowNivelUsuarios["DESCRICAO"]."</option>";
}
echo"
</select>
</td>
<td align='center'>
<button type='submit' class='btn btn-success btn-sm'>
SALVAR
<span class='glyphicon glyphicon-ok'>
</button>
</td>
</tr>";
}
echo"
</tbody>
</table>
";
?>
@Luiz MG:
object(mysqli_result)#5 (5) { ["current_field"]=> int(0) ["field_count"]=> int(6) ["lengths"]=> NULL ["num_rows"]=> int(14) ["type"]=> int(0) }
Logic found:
<?php
$x = 1;
$y = 1;
$z = 1;
echo "<table>
<thead>
<tr>
<th>SISTEMA</th>
<th>STATUS</th>
<th>NIVEL</th>
</tr>
</thead>";
while($x <= 5) {
echo"
<tbody>
<tr>
<td>
SISTEMA".$x."
</td>
<td>
<select>";
while($y <= 5) {
echo"<option>".$y."</option>";
$y++;
}
echo"</select>
</td>
<td>
<select>";
while($z <= 5) {
echo"<option>".$z."</option>";
$z++;
}
echo"</select>
</td>
</tr>
</tbody>";
$y = 1;
$z = 1;
$x++;
}
echo"</table> ";
This logic found is exactly what I need, how could I implement it in the previous code?
Good night! I am not an expert in php, but analyzing, you are giving 2 loops within a loop, right? Logically, the 2 internal loops will only pull data 1 time. Hence the problem.
– Sam