gpt4 book ai didi

javascript - 为所有值创建 1 个更新按钮

转载 作者:行者123 更新时间:2023-11-29 11:20:54 26 4
gpt4 key购买 nike

我仍在学习 php,并且我需要修改这个脚本。在此脚本中有多个更新按钮,我想创建另一个按钮来更新所有值。

这是我的脚本

<div class='tableContainer'>
<table>
<thead>
<th width='100px'>Pasaran</th>
<th width='150px'>Status</th>
</thead>
<tbody>
<?php foreach($pasaran as $b){ ?>
<tr>
<td width='101px'><?php echo $b['keterangan']; ?></td>
<td width='151px'>
<form action='<?php echo base_url('home/update_pasaran'); ?>' method='POST' class='uk-form'>
<input type='hidden' name='id_pasaran' value='<?php echo $b['id_pasaran']; ?>'/>
<select name='status_pasaran' class='uk-form-small'>
<option <?php if($b['status_pasaran']=='Offline') echo 'selected'; ?> >Offline</option>
<option <?php if($b['status_pasaran']=='Online') echo 'selected'; ?> >Online</option>
</select>
<button class='uk-button uk-button-primary uk-button-small'>Update</button>
</form>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>

我尝试添加此脚本

<form action='<?php echo base_url('home/update_pasaran'); ?>' method='POST' class='uk-form'>
<input type='hidden' name='id_pasaran' value='<?php echo $b['id_pasaran']; ?>'/>
<select name='status_pasaran' class='uk-form-small'>
<option <?php if($b['status_pasaran']=='Offline') echo 'selected'; ?> >Offline</option>
<option <?php if($b['status_pasaran']=='Online') echo 'selected'; ?> >Online</option>
</select>
<button class='uk-button uk-button-primary uk-button-small'>Update</button>
</form>

但当我单击按钮时唯一更新的是最后一行。

有人可以指导我吗?

最佳答案

这就是您的代码在客户端的样子

            <div class='tableContainer'>
<form action='post.php' method='POST' class='uk-form'>
<table>
<thead>
<th width='100px'>Pasaran</th>
<th width='150px'>Status</th>
</thead>
<tbody>
<?php foreach($pasaran as $b){ ?>
<tr>
<td width='101px'><?php echo $b['keterangan']; ?></td>
<td width='151px'>
<?php if($b['status_pasaran']=='Offline'){?>
<td><input type="checkbox" name="Online[]" value="DB_ID"></td>
<?php } else{ ?>
<td><input type="checkbox" name="Offline[]" value="DB_ID"></td>
<?php }?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<input type="submit" value="APPLY CHANGES">
</form>
</div>

文件 post.php 应该是这样的:

$online_array = $_POST["Online"];
$offline_array = $_POST["Offline"];

if(isset($online_array)&&!empty($online_array)){
foreach($online_array as $object_to_update){
/*Your query for the data base goes here*/

}
}

if(isset($offline_array)&&!empty($offline_array)){
foreach($offline_array as $object_to_update){
/*Your query for the data base goes here*/

}

}

关于javascript - 为所有值创建 1 个更新按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38948184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com