Keywords | data using in keyword to realize bulk deletion of data
Original: Small Wang Chai
The bulk deletion of data is often encountered in web programming. Our usual practice is to implement the bulk deletion of data through loops. But a program module is recycled too much, and the quality of the program module is reduced. Therefore, this article introduces the use of the IN keyword to achieve the bulk deletion of data.
Let's use an example to explain the in-keyword data-batch deletion
If we want to delete the data for this page: the relevant code is as follows:
managenews.asp <!--#include file= "conn.asp"-->
<% ' Database connection file I'm not going to say much more.%> <title> Management News </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<link rel= "stylesheet" href= ". /index/style.css "type=" Text/css ">
<script>
Function del ()//used to determine whether a record has been selected
{
var flag=true;
var temp= "";
var tmp;
if ((document.form1.answer.length+ "") = = "undefined") {tmp=1}else{tmp=document.form1.answer.length}
if (tmp==1) {
if (document.form1.answer.checked) {
Flag=false;
Temp=document.form1.answer.value
}
}else{
for (i=0;i<document.form1.answer.length;i++) {
if (document.form1.answer[i].checked) {
if (temp== "") {
Flag=false;
Temp=document.form1.answer[i].value
}else{
Flag=false;
Temp = temp + "," + document.form1.answer[i].value
}
}
}
}
if (flag) {alert ("Sorry, you have no choice!") ")}
else{Name=document.form1.name.value
Alert (name)
if (confirm) (Are you sure you want to delete?) ")){
Window.location= "delnews.asp?id=" + temp;
}
}
return!flag;
}
</script>
<body>
<script language=javascript>
function Checkall (all)//functions for judging all selected records
{
var a = Document.getelementsbyname ("answer");
for (var i=0; i<a.length; i++) a[i].checked = all.checked;
}
</script>
<%
Set Rs=server.createobject ("Adodb.recordset")
Sql= "SELECT * FROM News ORDER BY addtime Desc"
Rs.Open sql,conn,1,3%>
<% if Rs.eof then%>
<table width= "50%" border= "0" align= "center" id= "Table2" >
<tr>
<TD align= "center" >
No news!
</tr>
</table>
<% Else%>
<form method= "POST" Id=form1 name=form1>
<table width= "90%" border= "0" align= "center" class= "Tabdocborder" id= "Table3" >
<tr>
<td>
<table width= "80%" align= "center" id=tabdocmain border= ' 1 ' cellspacing= ' 0 ' cellpadding= ' 0 ' bordercolorlight= ' 82B4DD ' bordercolor= ' #b6d3eb ' class= "Tabdocmain" >
<thead>
<tr>
<TD colspan= "7" align= "Center" >
News Management Center
</td>
</tr>
</thead>
<tbody>
<tr>
<TD align=center>
Delete Box
</td>
<TD align=center>
News Headlines
</td>
<TD align=center>
Publish Time
</td>
<TD align=center>
Management
</td>
</tr>
<%
Do as not rs.eof
%>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.