Using in keyword to realize bulk deletion of data

Source: Internet
Author: User
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>
&LT;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>
&LT;TD colspan= "7" align= "Center" >
News Management Center
</td>
</tr>
</thead>
<tbody>
<tr>
&LT;TD align=center>
Delete Box
</td>
&LT;TD align=center>
News Headlines
</td>
&LT;TD align=center>
Publish Time
</td>
&LT;TD align=center>
Management
</td>
</tr>
<%
Do as not rs.eof
%>

<tr>
&LT;TD align=center><input type= "checkbox" name= "Answer" value= "<%=rs" ("id")%> "id=" Checkbox1 ">
</td>
&LT;TD align=left><%if Len (rs ("title")) <=30 Then%><%=rs ("title")%><%else%>
<%= (Left (RS ("title"),)%&gt ....
<%end if%></td>
&LT;TD align=left><%=rs ("Addtime")%></td>
&LT;TD align=center><a href= "editnews.asp?id=<%=rs (" id ")%>" > Edit </a></td>
</tr>
</tbody>
<%
Rs.movenext
Loop
%>

<tr>
&LT;TD colspan= "7" align= "Center" >
<input type= "checkbox" Name= "Chkall" value= "on" onclick= "Checkall (This)" id= "Checkbox2" > select all Display News
<input type= "button" Name= "Btndelete" value= "delete" Style= ' font-family: Song body; Font-size:9pt ' onclick= ' del () "id=" Button1 ">
</td>
</tr>
</table>
</form>
</td>
</tr>
<%end if%>
</table>
<% Set rs=nothing
Conn.close
Set conn=nothing
%>
</body>
delnews.asp file
<!--#include file= "conn.asp"-->
<%
Arrdel=request ("id")
' Response.Write Arrdel
Sql= "Delete from news where id" ("&arrdel&")
' Response.Write sql
Conn. Execute SQL
Set conn=nothing
Response.Write "<script Language=javascript>alert (' Delete success! ');"
Response.Write "Javascript:history.go ( -1) </SCRIPT>"
Response.End
%>



Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.