我如何从数据库中编辑数据循环期间获取选择选项中的数据?



我的代码有一个问题。我使用模型来更新数据,但在我的表单中有一个选择选项,当我需要填充所有数据时,我发现只有一行填充在其中。如果我必须用<?php while ($row = mysqli_fetch_array($query)) {?>填充那个选项中的值。在该选项字段中填充所有行,但在需要填充所有行数据的列表中,它只填充一个。

<?php 
include('../Tools/connection.php');
$query = mysqli_query($db,"SELECT abl_atms.atmCode,abl_atms.atmID,abl_atms.branchID, abl_branch.name,abl_branch.bid
FROM abl_atms
INNER JOIN abl_branch ON abl_branch.bid = abl_atms.branchID");
while ($row = mysqli_fetch_array($query)) {
$id = $row['atmID'];
$id = $row['branchID']
?>
<tr>
<td><?php echo strtoupper($row['atmID']);?></td>
<td><?php echo ucwords($row['atmCode']).'- '.strtolower($row['name']);?></td>
<td><?php echo strtoupper($row['name']);?></td>
<td class="pull-right">
<button class="btn-success btn-xs" data-toggle="modal" href="#atm<?php echo $row['atmID'];?>" 
data-toggle="tooltip" title="Edit">
<i class="fa fa-pencil-square-o" aria-hidden="true"></i></button>
<button class="btn-danger btn-xs" title="Delete" data-toggle="modal"
href="#delete<?php echo $row['atmID'];?>" data-toggle="tooltip">
<i class="fa fa-trash-o" aria-hidden="true"></i>
</button>
</td>
</tr>



<div class="modal fade" id="atm<?php echo $row['atmID'];?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="card" style="border-left: 4px solid coral">
<div class="card-header">
<div class="alert alert-warning" role="alert">
Update Atm information
</div>
</div>
<div class="card-body">
<form class="was-validated" action="abl_atms.php" method="POST">
<fieldset class="form-group">
<label for="exampleInputEmail1" class="bmd-label-static"><i class="fa fa-barcode" aria-hidden="true"></i> ATM CODE</label>
<input type="text" class="form-control" name="atmCode" value="<?php echo ucwords($row['atmCode']);?>" placeholder="Type ATM Identification CODE" required>
</fieldset>
<input class="form-control" name="atmID" type="hidden" value="<?php echo $row['atmID'];?>">
<fieldset class="form-group">
<label for="exampleInputEmail1" class="bmd-label-static"><i class="fa fa-snowflake-o" aria-hidden="true"></i> ATM BRANCH</label>
<select class="custom-select" required name="branchID">
<option value="">Select Branch Name</option>
<?php
while ($row = mysqli_fetch_array($query)) {
?>
<option value="<?php echo $row['branchID']; ?>"<?php if ($id == $row['branchID']) 
{ echo 'selected="selected"'; } ?>><?php echo $row['name']; ?></option> 
<?php 
}
?>                        
</select>
</fieldset>                            
<button type="submit" class="btn btn-raised btn-warning btn-block" name="editAtm">
<i class="fa fa-floppy-o" aria-hidden="true"></i> Confirm & Update
</button>
</form>
</div>
</div>
</div>
</div>
</div> 
<?php 
}
?>       
</tbody>
</table>
</div>
</div>
</div>

您可以将结果存储在数组中,然后循环遍历结果。

$query = mysqli_query($db,"SELECT abl_atms.atmCode,abl_atms.atmID,abl_atms.branchID,abl_branch.name,abl_branch.bid 
FROM abl_atms 
INNER JOIN abl_branch 
ON abl_branch.bid = abl_atms.branchID");
$results = mysqli_fetch_all(MYSQLI_ASSOC);
foreach($results as $v){
// Your Code....
foreach($results as $vi){
// Your Selection Options...
}
}

相关内容

  • 没有找到相关文章

最新更新