html - How to get Input or Select tag value inside a loop in PHP?
one text
Im working with my project it have table composed of text and select tag (dropdown).
I used php for loop to display data per row using <tr>
tag.
Sample code of my tr tag
<?php
$index = 0;
while ($index < sizeof($json)) :
?>
<tr>
<?php ... ?>
<td><?php echo $sample ?></td>
<td><?php echo $sample ?></td>
<td><?php echo $sample ?></td>
<td>
<form id="myForm" action="include/test-inc.php" method="POST">
<div class="dropdown">
<select class="form-select" aria-label="Def ault select example" name="select[<?php echo $index; ?>]">
<option selected value="false">False</option>
<option value="true">True</option>
</select>
</div>
</form>
</td>
</tr>
<?php
$index++;
endwhile;
?>
<input type="submit" form="myForm" name="saveBtn" class="btn btn-primary w-25" value="SAVE">
Code for test-inc.php
if (isset($_POST['saveBtn'])) {
print_r($_POST['select']);
}
The test-inc.php return the output like this
Array ( [0] => false )
It only get the first item on a row in a table, not in a whole.
How I can get all those select tag value??
Source