gpt4 book ai didi

php - 如何将 DATA 转换为输入字段 - PHP

转载 作者:可可西里 更新时间:2023-11-01 08:09:01 24 4
gpt4 key购买 nike

我正在尝试在此处创建表,以便我可以从 mysql 中提取所有数据。

enter image description here

我在我的字段上添加了两个额外的按钮来编辑和删除选定的特定项目。

现在我不确定如何将文本转换为输入字段(每当我单击“编辑”按钮时)然后编辑信息并使编辑按钮变为保存(在编辑模式下,输入正在显示)按钮,以便我可以进行更改/更新。我也不确定如何获取 ID 以便更新该特定字段。

到目前为止,这是我的代码:

  function readData(){
global $connection;

$query = "SELECT * FROM users";

$result = mysqli_query($connection, $query);

if(!$result) {
die('Query FAILED' . mysqli_error());
}

while($row = mysqli_fetch_assoc($result)){
$id = $row['id'];
$username = $row['username'];
$password = $row['password'];

echo '<tr>';
echo "<td>$id</td>";
echo "<td>$username</td>";
echo "<td>$password</td>";
echo "<td><button id='edit' name='edit'>EDIT</button></td>";
echo "<td><button id='delete' name='delete'>DELETE</button></td>";
echo '</tr>';
}
}

function editDate(){
global $connection;

$query = "UPDATE users SET ";
$query .= "username = '$username', ";
$query .= "password = '$password' ";
$query .= "WHERE id='$id'";

$result = mysqli_query($connection, $query);
if(!$result){
die('QUERY FAILED' . mysqli_error($connection));
}
}

这是我的主文件...

<?php 
include 'functions.php';
?>

<?php include 'includes/header.php' ?>


<table style="width: 200px;" border="1">
<tr>
<th>ID</th>
<th>USERNAME</th>
<th>PASSWORD</th>
<th>EDIT</th>
<th>DELETE</th>
</tr>
<tr>
<?php readData(); ?>
</tr>
</table>


<?php include 'includes/footer.php' ?>

知道如何实现吗?

最佳答案

当单击任何行的数据时,您必须调用 onclick jquery 事件。我认为它会对你有很大帮助。 https://codewithmark.com/easily-edit-html-table-rows-or-cells-with-jquery

还有 fiddle 代码:- http://jsfiddle.net/9KEGd/

享受代码

关于php - 如何将 DATA 转换为输入字段 - PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51280416/

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