[英]How to delete rows separated by comma?
Hi I have here a simple question. 嗨,我这里有一个简单的问题。 I can get id from the url of the site and get that id by using $_GET['']
function in php. 我可以从网站的网址获取ID,并通过在PHP中使用$_GET['']
函数获取该ID。 My link goes like this: .php?id=10,11,&from=user
. 我的链接是这样的: .php?id=10,11,&from=user
。 What I want to know is that if there is a delete sql for the id of the user. 我想知道的是,是否存在用于用户ID的删除SQL。
if($_POST['action']){
$id = $_GET['id'];
$from = $_GET['from'];
if(!empty($id))
{
$statement = " <-- SQL STATEMENT --> ";
$result = mysql_query($statement);
if($result)
{header("location:user.php");}
}
EDIT Okay. 编辑好吧。 My table goes like this: 我的桌子是这样的:
ID, Username, Password, Role Checkbox
1 test test Admin []
2 branch branch Manager []
3 hello hello Manager []
I have a checkbox and I get those values using a function in javascript 我有一个复选框,并使用javascript中的函数获取这些值
var id="";
$("#form1 input:checkbox:checked").each(function(){
id = $(this).data('id')+' '+id;
});
$.pgwModal({
url: 'modaldeleteuser.php?id='+id,
modalData : {
id : ''+id
},
loading: '<span style="text-align:center">Loading in progress</span>',
title: 'Delete User',
close: false
});
And I pass the value in to modaldelete.php through the URL using a script of a modal to pass it to a php variable 然后我使用模态脚本通过URL将值传递给modaldelete.php并将其传递给php变量
<div>
<?php
$id = $_GET['id'];
?>
<form action="submit.php?id=<?php echo $id;?>&from=user" method="post" enctype="multipart/form-data">
<p class="text-center">Are you sure you want to delete user(s) <?php echo $_GET['id'];?> from user table?</p>
<!-- <p id ="demo" class="text-center"></p> -->
<p class="text-center"><input type="hidden" name="action" value="delete"/>
<button class="btn btn-danger">Delete</button> <a href="javascript:void(0)" class="btn btn-inverse" onclick="$.pgwModal('close');">Cancel</a></p>
</form>
</div>
So for the submit.php 所以对于submit.php
if($_POST['action']=="delete") {
if(!empty($_GET['id']))
{
$statement = "DELETE FROM user WHERE `Employee_ID` IN (" . implode(", ",$_GET['id']) . ")";
$result = mysqlparser($statement, $db);
header("location:user.php?delete=1");
}
else
{header("location:user.php?delete=2"); }
}
So now. 所以现在。 My question again.. How can I delete the id from the URL which is separated by comma? 我的问题又来了。如何从用逗号分隔的URL中删除ID?
$from = mysql_real_escape_string($_GET['from']); // Protect against SQL injection
$ids = implode(',', array_map('intval', explode(',', $_GET['id'])));
$statement = "DELETE FROM yourtable
WHERE from = '$from' AND id IN ($ids)";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.