我正在使用 php 连接到数据库并将表格的所有行显示为网页上的表格。现在我想要的是在每一行中都有一个复选框和一个隐藏按钮,这样当我点击一行中的一个复选框时,该行的相应按钮变得可见,当我点击该按钮时,该行将被删除。
这是我的php代码。我正在使用 wordpress,因为 wordpress 不允许在页面上使用 php,所以我使用插件 shortcode-exec-php 在 wordpress 页面上启用 php。但我认为这更像是一个编程问题,而不是 wordpress 支持问题。
// Connect to the database
$dbLink = new mysqli('127.0.0.1', 'abc', '123', 'test');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
// Query for a list of all existing files
$sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`';
$result = $dbLink->query($sql);
// Check if it was successfull
if($result) {
// Make sure there are some files in there
if($result->num_rows == 0) {
echo '<p>There are no files in the database</p>';
}
else {
// Print the top of a table
echo '<table width="100%">
<tr>
<td><b>Name</b></td>
<td><b>Mime</b></td>
<td><b>Size (bytes)</b></td>
<td><b>Created</b></td>
<td><b> </b></td>
</tr>';
// Print each file
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>{$row['name']}</td>
<td>{$row['mime']}</td>
<td>{$row['size']}</td>
<td>{$row['created']}</td>
<td><a href='get_file.php?id={$row['id']}'>Download</a></td>
//here i want a code that insert a checkbox and a hidden button with the above mentioned functionalty
</tr>";
}
// Close table
echo "</table>";
}
// Free the result
$result->free();
}
else
{
echo 'Error! SQL query failed:';
echo "<pre>{$dbLink->error}</pre>";
}
// Close the mysql connection
$dbLink->close();
有谁能够帮我?
如果您提到 javascript,请告诉我一种将它与现有代码一起使用的方法。