作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试在此处创建表,以便我可以从 mysql 中提取所有数据。
我在我的字段上添加了两个额外的按钮来编辑和删除选定的特定项目。
现在我不确定如何将文本转换为输入字段(每当我单击“编辑”按钮时)然后编辑信息并使编辑按钮变为保存(在编辑模式下,输入正在显示)按钮,以便我可以进行更改/更新。我也不确定如何获取 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/
我是一名优秀的程序员,十分优秀!