简体   繁体   English

在一个视图,PHP,MYSQL,HTML中删除单个和多个条目

[英]Delete Single and Multiple entries in one View, PHP, MYSQL, HTML

How do I achieve the following? 我如何实现以下目标?

I have a list of entries. 我有一个条目列表。 当前实施

I want to be able to delete a single entry via the right "x" 我希望能够通过右侧的“ x”删除单个条目

But also I would like to be able to select multiple entries via the checkboxes on the left. 但我也希望能够通过左侧的复选框选择多个条目。 After that, obviously clicking the "delete selected entries" at the bottom. 之后,显然单击底部的“删除选定的条目”。

At the moment, all of this is in one form. 目前,所有这些都是一种形式。 Everything is links at the moment, not really what I want at all because it doesnt work. 目前,所有内容都是链接,不是我想要的,因为它不起作用。

Can anyone help me with a strategy or implementation that would enable me to get this working? 谁能帮助我制定使我能够正常工作的策略或实施方案?

Heres the html code at the moment, I create it dynamically with some PHP, request if you want to see: :) 现在是继承人的html代码,我用一些PHP动态创建了它,如果您想看,请请求::)

<form class="learnfest_form" method="post" action="">
    <h2>Delete a Learnfest Entry <small>Select an entry to delete</small></h2>
    <hr>
            <ul class="list-group checked-list-box">
                    <li class="list-group-item"><input type="checkbox" value="c1e42a9f9cfbdad684fa5a107a9967cef96a8a6e">&nbsp; L01<a class="pull-right" href="c1e42a9f9cfbdad684fa5a107a9967cef96a8a6e" onclick="return confirm('Are you sure?');"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></li>
                    <li class="list-group-item"><input type="checkbox" value="0c0203b6b6d5105a3e72deac0b61be61236b1ff7">&nbsp; L02<a class="pull-right" href="0c0203b6b6d5105a3e72deac0b61be61236b1ff7" onclick="return confirm('Are you sure?');"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></li>
                    <li class="list-group-item"><input type="checkbox" value="99a5cbf3ff728b5d6f3f524d301edc6a5d38feb9">&nbsp; L03<a class="pull-right" href="99a5cbf3ff728b5d6f3f524d301edc6a5d38feb9" onclick="return confirm('Are you sure?');"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></li>
                    <li class="list-group-item"><input type="checkbox" value="31729ebd6fa5fcb0f17cdc1e3e5fe3c861149782">&nbsp; L04<a class="pull-right" href="31729ebd6fa5fcb0f17cdc1e3e5fe3c861149782" onclick="return confirm('Are you sure?');"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></li>
                </ul>
        <div class="panel panel-default">
            <div class="panel-body">
                Delete Selected Entries <a href="#"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>
            </div>
        </div>
    </form>

When you click on Delete Selected Entries retrieve all .list-group-item checkbox:checked elements and make an AJAX request to your php page to delete all of them. 当您单击“ 删除所选条目”时,检索所有.list-group-item checkbox:checked元素,并向您的php页面发出AJAX请求以删除所有这些元素。 Your request will be something like this: 您的请求将如下所示:

{
  elementstodelete: [
    'c1e42a9f9cfbdad684fa5a107a9967cef96a8a6e',
    '0c0203b6b6d5105a3e72deac0b61be61236b1ff7'
  ]
}

On server side you use json_decode() to read all the elements and you'll make the magic query to delete them. 在服务器端,您使用json_decode()读取所有元素,然后进行魔术查询将其删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM