Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中单击复选框后显示不可见的按钮?_Php - Fatal编程技术网

如何在php中单击复选框后显示不可见的按钮?

如何在php中单击复选框后显示不可见的按钮?,php,Php,我正在使用php连接到数据库,并将表的所有行显示为网页上的表。现在我想要的是在每一行中都有一个复选框和一个隐藏按钮,这样当我单击某一行中的复选框时,该行的相应按钮将可见,当我单击该按钮时,该行将被删除 这是我的php代码。我正在使用wordpress,因为wordpress不允许在页面上使用php,所以我使用了一个插件shortcode exec php来在wordpress页面上启用php。但我认为这更像是一个编程问题,而不是wordpress支持问题 // Connect to the da

我正在使用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>&nbsp;</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();
//连接到数据库
$dbLink=newmysqli('127.0.0.1','abc','123','test');
if(mysqli\u connect\u errno()){
die(“MySQL连接失败:”.mysqli_connect_error());
} 
//查询所有现有文件的列表
$sql='选择'id','name','mime','size','created','FROM'file`;
$result=$dbLink->query($sql);
//检查是否成功
如果($结果){
//确保里面有一些文件
如果($result->num_rows==0){
echo“数据库中没有文件”

; } 否则{ //打印表格的顶部 回声' 名称 哑剧表演 大小(字节) 创建 '; //打印每个文件 而($row=$result->fetch_assoc()){ 回声“ {$row['name']} {$row['mime']} {$row['size']} {$row['created']} //这里我想要一个代码,插入一个复选框和一个具有上述功能的隐藏按钮 "; } //闭桌 回声“; } //释放结果 $result->free(); } 其他的 { echo“错误!SQL查询失败:”; 回显“{$dbLink->error}”; } //关闭mysql连接 $dbLink->close();
有人能帮我吗


如果您提到javascript,请告诉我一种将其与现有代码一起使用的方法。

下面是一个可能对您有所帮助的代码(使用jquery):

Php:


这里是一个演示:

任何你想在网页上发生而不需要重新加载的事情都必须用Javascript来完成。所以这不是一个免费的编码服务。您需要将JS添加到执行此操作的页面中。如果您使用jQuery,这可能是最简单的,它使编写处理程序来处理与您单击的对象在同一行上的元素变得更容易。请。谢谢。但我没有问完整的问题是我的错误。实际上,我想有两个按钮删除和编辑。您的解决方案仅适用于删除。如何以相同的方式使用编辑。还有一件事我想在点击删除和编辑时更新数据库。检查我的更新提琴..我添加了编辑选项..:)并使用ajax在删除或编辑时更新数据库。好的,谢谢,但还有一件事我怎么知道在ajax中点击了哪一行的删除按钮来更新数据库,同时显示while循环中的每一行在输入类型
中隐藏的该记录的唯一id,删除时获取该唯一id。通过这种方式,您可以将该唯一id与该表的主键进行比较,并删除相应的行。抱歉,笑话,但我无法这样做。您能帮我做吗。我是php jquery的新手。如何获取行id?如何将其传递给ajax。没用
 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>
             <td><input type='checkbox' class='checkbox'><input type='button' style='display:none' value='delete' name='delete'><input type='button' style='display:none' value='edit'  name='edit'></td>
         </tr>";
$(document).ready(function(){
 $("input[type=checkbox]").on("click", function () {
   ($(this).is(":checked")) ? $(this).nextAll("input").show() : $(this).nextAll("input").hide();
 });
 $("input[name='delete']").on("click", function () {
   $(this).closest("table tr").remove();
 });
   $("input[name='edit']").on("click", function () {
    $(this).closest("tr").attr("contenteditable",true).focus();
  });
});