[英]delete multiple rows with checkbox
i have the following jquery code to delete multiple rows of table: 我有以下jquery代码删除多行表:
$(function(){
$("a.delete").click(function(){
page=$(this).attr("href");
ids=new Array()
a=0;
$("input.chk:checked").each(function(){
ids[a]=$(this).val();
a++;
})
if(confirm("Are you sure want to delete?")){
el=$(this)
$.ajax({
url:page,
data:"id="+ids,
type:"GET",
success:function(res)
{
if(res==1)
{
$("input.chk:checked").each(function(){
$(this).parent().parent().remove();
})
}
}
})
}
return false;
})
})
checkbox (value with name question_id is ok, the checkbox is inside a while loop): 复选框(名称为question_id的值正常,复选框位于while循环内):
<input name="chk[]" class="chk" type="checkbox" value="'<?php echo $row1['question_id'];?>'" />
delete link (outside of loop): 删除链接(循环外):
<a href="delete_quiz_questions.php" class="delete">delete</a>
and the php page to delete the records: 和删除记录的php页面:
<?php
session_start();
include('connect_db.php');
$delete_id = $_GET['id'];
$id = count($delete_id);
if (count($id) > 0){
foreach ($delete_id as $id_d){
$sql = "DELETE FROM quiz_questions WHERE id_questions ='$id_d' AND id_quiz ='".$_SESSION['quiz_id']."'";
$delete = mysql_query($sql);
}
}
?>
when i click in href button to delete record show me this message 当我点击href按钮删除记录时显示此消息
Notice: Undefined index: id in C:\wamp\www\diplomatiki\delete_quiz_questions.php on line 5
Warning: Invalid argument supplied for foreach() in C:\wamp\www\diplomatiki\delete_quiz_questions.php on line 11
Notice: Undefined variable: delete in C:\wamp\www\diplomatiki\delete_quiz_questions.php on line 18
can you help me please?? 你能帮我吗??
the php page to send the data php页面发送数据
$result=mysql_query("SELECT * FROM quiz_questions WHERE id_quiz='".$quiz_id."' ");
if(mysql_num_rows($result)>0){
$index = 1;
while($row=mysql_fetch_array($result))
{
$result1=mysql_query("SELECT * FROM questions WHERE question_id ='".$row['id_questions']."'");
if(mysql_num_rows($result1)>0){
while($row1=mysql_fetch_array($result1))
{
$result2=mysql_query("SELECT * FROM question_".$row1['type']." WHERE id_question='".$row1['question_id']."' LIMIT 1");
if(mysql_num_rows($result2)>0){
$row2=mysql_fetch_array($result2);
?>
<tr>
<td><?php echo $index++; ?> </td>
<td><input name="chk[]" class="chk" type="checkbox" value="'<?php echo $row1['question_id'];?>'" /></td>
<td><?php echo $row1['type']; ?></td>
<td><?php echo $row2['question']; ?></td>
</tr>
<?php }}
}
}
echo '<input type="hidden" name="quiz_id" id="quiz_id" style="text-align: center" value="' . $quiz_id . '" size=5/>';
?>
</tbody>
</table>
<caption><a href="delete_quiz_questions.php" class="delete">delete</a></caption>
<?php } else echo 'sorry'; ?>
You must use explode
to convert the ID string to an Array
. 您必须使用
explode
将ID字符串转换为Array
。
$delete_id = explode(",", $_GET['id'])
$id = count($delete_id);
if (count($id) > 0)
Initially you must do this. 最初你必须这样做。
if (isset($_GET['id'])) {
So You will not get any Notice
or Warning
所以你不会收到任何
Notice
或Warning
session_start();
include('connect_db.php');
if (isset($_GET['id'])) {
$delete_id = explode(",", $_GET['id'])
$id = count($delete_id);
if (count($id) > 0)
{
foreach ($delete_id as $id_d)
{
$sql = "DELETE FROM quiz_questions WHERE id_questions ='$id_d' AND id_quiz ='".$_SESSION['quiz_id']."'";
$delete = mysql_query($sql);
}
}
}
首先,您必须检查会话quiz_id是否存在。如果存在,您应该检查此会话是否分配了任何值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.