gpt4 book ai didi

php - 更新表格行中的数据[PHP]

转载 作者:行者123 更新时间:2023-11-29 02:43:45 24 4
gpt4 key购买 nike

我有一个标准的 HTML 表格,表格中的每一行都是使用循环从数据库表格生成的。

在每一行的末尾我都有一个更新按钮,我想用它来更新表字段中的数据。

下图展示了这个概念。

enter image description here

表格本身

<div class="container" id="users">

<div class="row">
<div class="col-md-12">
<div class="table-responsive">

<form method="post" action="">

<table class="table table-bordered table-hover table-striped tablesorter">
<thead>

<tr>

<th width="10%" style="text-align:left">Forename</th>
<th width="15%" style="text-align:left">Surname</th>
<th width="35%" style="text-align:left">Email</th>
<th width="30%" style="text-align:left">Permissions</th>
<th width="5%" style="text-align:left">Update</th>
<th width="5%" style="text-align:left">Delete</th>

</tr>
</thead>
<tbody>
<tr>
<!--here showing results in the table -->
<?php

$adminquery = "SELECT * FROM admin ORDER by user_id DESC";
$IDlist = mysqli_query($dbconEDB, $adminquery);

while($rowlist=mysqli_fetch_array($IDlist))//while look to fetch the result and store in a array $row.
{
$user_id = $rowlist["user_id"];
$admin_email = $rowlist["admin_email"];
$forename = $rowlist["forename"];
$surname = $rowlist["surname"];

$JPortal = $rowlist["JPortal"];
$Tenders = $rowlist["Tenders"];
$News= $rowlist["News"];
$Events = $rowlist["Events"];
$Users= $rowlist["Users="] ;

?>

<td style="text-align:left">
<div class="form-group">
<input name="user_id" id="user_id" type="text" class="form-control" value="<?php echo $user_id;?>">
<input name="forename" id="forename" type="text" class="form-control" value="<?php echo $forename;?>">
<div class="hidden"> <?php echo $forename;?></div>
</div>
</td>

<td style="text-align:left">
<div class="form-group">
<input name="forename" id="surname" type="text" class="form-control" value="<?php echo $surname;?>">
<div class="hidden"> <?php echo $surname;?></div>
</div>
</td>

<td style="text-align:center">
<div class="form-group">
<input name="admin_email" id="admin_email" type="text" class="form-control" value="<?php echo $admin_email;?>">
<div class="hidden"> <?php echo $admin_email;?></div>
</div>
</td>

<td style="text-align:center">


<label>
<input name="JPortal" type="checkbox" id="JPortal" value="1" <?php if ($JPortal == 1) echo "checked='checked'" ;?>> Jobs
</label>

<label>
<input type="checkbox" name="Tenders" value="1" id="Tenders" <?php if ($Tenders == 1) echo "checked='checked'" ;?>> News
</label>

<label>
<input type="checkbox" name="News" value="1" id="News" <?php if ($News == 1) echo "checked='checked'" ;?>> Tenders
</label>

<label>
<input type="checkbox" name="Events" value="1" id="Events" <?php if ($Events == 1) echo "checked='checked'" ;?>> Events
</label>

<label>
<input type="checkbox" name="Users" value="1" id="Users" <?php if ($Users == 1) echo "checked='checked'" ;?>> Users
</label>


</td>

<td style="text-align:center">

<input class="btn btn-newable " type="submit" value="Update" name="EDBsubmit">
</td>

<td style="text-align:center">
<a href="users.php?user=<?php echo $user_id; ?>"><button class="btn btn-newable">update2</button></a>
</td>

</tr>
<?php } ?>

</tbody>
</table>

</form>

</div>
</div>

</div>

我想我刚刚休息了一天,实际上可以将表格包裹在表格的每一行周围。

最佳答案

一个简单的方法是在每个 TD 中有一个包含更新按钮的表单。只需将此按钮设为输入[type=submit],然后在此表单中添加一个包含您行行ID 的input[type=hidden]。然后,您基本上可以在 $_POST 中获取 ID。

示例:

<td class="actions">
<form method="post">
<input type="hidden" name="row_id" value="<?php echo $line['id']; ?>"/>
<input type="submit" value="Update"/>
</form>
</td>

关于php - 更新表格行中的数据[PHP],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46196208/

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