Forums
This topic is locked
delete multiple records and delete associated file
Posted 21 Jan 2002 14:51:57
1
has voted
21 Jan 2002 14:51:57 David Behan posted:
I am looking for a way of deleting multiple records and at the same time delete the associated .jpg file too. The delete functionality is working grand and is below. Now how do I get it to delete the file as well. Have a look and see what you think. Cheers...<b>Page 1 - Listing Page</b>
<font color=red><b>Before html...</font id=red></b>
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/property.asp" -->
<%
Dim RsProperty__MMColParam
RsProperty__MMColParam = "1"
if (Request.QueryString("type" <> "" then RsProperty__MMColParam = Request.QueryString("type"
%>
<%
set RsProperty = Server.CreateObject("ADODB.Recordset"
RsProperty.ActiveConnection = MM_property_STRING
RsProperty.Source = "SELECT * FROM tbl_listing WHERE type = '" + Replace(RsProperty__MMColParam, "'", "''" + "' ORDER BY ranking ASC"
RsProperty.CursorType = 0
RsProperty.CursorLocation = 2
RsProperty.LockType = 3
RsProperty.Open()
RsProperty_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
RsProperty_numRows = RsProperty_numRows + Repeat1__numRows
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables
' set the record count
RsProperty_total = RsProperty.RecordCount
' set the number of rows displayed on this page
If (RsProperty_numRows < 0) Then
RsProperty_numRows = RsProperty_total
Elseif (RsProperty_numRows = 0) Then
RsProperty_numRows = 1
End If
' set the first and last displayed record
RsProperty_first = 1
RsProperty_last = RsProperty_first + RsProperty_numRows - 1
' if we have the correct record count, check the other stats
If (RsProperty_total <> -1) Then
If (RsProperty_first > RsProperty_total) Then RsProperty_first = RsProperty_total
If (RsProperty_last > RsProperty_total) Then RsProperty_last = RsProperty_total
If (RsProperty_numRows > RsProperty_total) Then RsProperty_numRows = RsProperty_total
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them
If (RsProperty_total = -1) Then
' count the total records by iterating through the recordset
RsProperty_total=0
While (Not RsProperty.EOF)
RsProperty_total = RsProperty_total + 1
RsProperty.MoveNext
Wend
' reset the cursor to the beginning
If (RsProperty.CursorType > 0) Then
RsProperty.MoveFirst
Else
RsProperty.Requery
End If
' set the number of rows displayed on this page
If (RsProperty_numRows < 0 Or RsProperty_numRows > RsProperty_total) Then
RsProperty_numRows = RsProperty_total
End If
' set the first and last displayed record
RsProperty_first = 1
RsProperty_last = RsProperty_first + RsProperty_numRows - 1
If (RsProperty_first > RsProperty_total) Then RsProperty_first = RsProperty_total
If (RsProperty_last > RsProperty_total) Then RsProperty_last = RsProperty_total
End If
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters
' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "" Then MM_removeList = MM_removeList & "&" & MM_paramName & "="
MM_keepURL="":MM_keepForm="":MM_keepBoth="":MM_keepNone=""
' add the URL parameters to the MM_keepURL string
For Each Item In Request.QueryString
NextItem = "&" & Item & "="
If (InStr(1,MM_removeList,NextItem,1) = 0) Then
MM_keepURL = MM_keepURL & NextItem & Server.URLencode(Request.QueryString(Item))
End If
Next
' add the Form variables to the MM_keepForm string
For Each Item In Request.Form
NextItem = "&" & Item & "="
If (InStr(1,MM_removeList,NextItem,1) = 0) Then
MM_keepForm = MM_keepForm & NextItem & Server.URLencode(Request.Form(Item))
End If
Next
' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
if (MM_keepBoth <> "" Then MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
if (MM_keepURL <> "" Then MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
if (MM_keepForm <> "" Then MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
If (firstItem <> "" Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%>
<font color=red><b>Repeat Region and Form for Delete</font id=red></b>
<form name="form1" method="post" action="listing_del.asp" onSubmit="GP_popupConfirmMsg('Are you sure you want to delete the selected properties?');return document.MM_returnValue">
<% If Not RsProperty.EOF Or Not RsProperty.BOF Then %>
<p><span class="medbold">Total:</span> <%=(RsProperty_total)%> Properties</p>
<table border="0" cellpadding="0" cellspacing="0" class="mednormal" width="100%">
<% Dim iCount
iCount = 1
%>
<%
While ((Repeat1__numRows <> 0) AND (NOT RsProperty.EOF))
%>
<tr <% if repeat1__numrows mod 2 = 0 then %>bgcolor="#EFEFEF"<% End If %> bgcolor="#DFDFDF">
<td align="default" width="30">
<div align="center">
<input type="checkbox" name="<%= (iCount & ".Check" %>" value="Remove">
</div>
</td>
<td align="default">
<% If RsProperty.Fields.Item("onsite".Value = ("Yes" Then 'script %>
<span class="medbold"><%=(RsProperty.Fields.Item("address".Value)%></span>
<% End If ' end If RsProperty.Fields.Item("onsite".Value = ("Yes" script %>
<% If RsProperty.Fields.Item("onsite".Value = ("No" Then 'script %>
<span class="mednormal"><%=(RsProperty.Fields.Item("address".Value)%></span>
<% End If ' end If RsProperty.Fields.Item("onsite".Value = ("No" script %>
<input type="hidden" name="<%= (iCount & ".ID" %>" value="<%=(RsProperty.Fields.Item("property_id".Value)%>">
</td>
<td align="default" width="80">
<div align="center"><%=(RsProperty.Fields.Item("status".Value)%></div>
</td>
<td align="default" width="130">
<div align="right"><a href="listing_edit.asp?<%= MM_keepURL & MM_joinChar(MM_keepURL) & "property_id=" & RsProperty.Fields.Item("property_id".Value %>"><img src="images/edit.gif" width="18" height="16" alt="Edit this property's details" border="0"></a>
<a href="listing_picsm.asp?<%= MM_keepURL & MM_joinChar(MM_keepURL) & "property_id=" & RsProperty.Fields.Item("property_id".Value %>"><img src="images/small.gif" width="18" height="16" border="0" alt="Modify or delete the small image for this property"></a>
<a href="listing_piclg.asp?<%= MM_keepURL & MM_joinChar(MM_keepURL) & "property_id=" & RsProperty.Fields.Item("property_id".Value %>"><img src="images/large.gif" width="18" height="16" border="0" alt="Modify or delete the large image for this property"></a>
<a href="listing_reset.asp?<%= MM_keepURL & MM_joinChar(MM_keepURL) & "property_id=" & RsProperty.Fields.Item("property_id".Value %>"><img src="images/reset.gif" width="18" height="16" alt="Reset the pictures associated with this property" border="0"></a>
<a href="print.asp?<%= MM_keepURL & MM_joinChar(MM_keepURL) & "property_id=" & RsProperty.Fields.Item("property_id".Value %>" target="_blank"><img src="images/print.gif" width="18" height="16" alt="Print this property's details on to your headed paper" border="0"></a></div>
</td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
RsProperty.MoveNext()
iCount = iCount + 1
Wend
%>
</table>
<p><span class="medboldalt">NOTE</span><span class="medbold">:</span>
The <span class="medbold">addresses</span> of properties that have been
temporarily switched off are shown in plain text, live items are shown
in bold. Properties are in the order they will appear on the live website.</p>
<p>
<input type="submit" name="Submit" value="Delete Selected Properties">
<input type="hidden" name="Count" value="<%= iCount - 1 %>">
</p>
<% End If ' end Not RsProperty.EOF Or NOT RsProperty.BOF %>
</form>
delete page below...
---------------------
David Behan - bmor.com
Replies
Replied 21 Jan 2002 14:55:18
21 Jan 2002 14:55:18 David Behan replied:
Delete page has the following code:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/property.asp" -->
<%
Response.Buffer = True
Dim iCount
iCount = Request.Form("Count"
Dim strID, strCheck
Dim strSQL
Dim iLoop
For iLoop = 0 to iCount
strCheck = Request(iLoop & ".Check"
strID = Request(iLoop & ".ID"
if strCheck = "Remove" then
set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_property_STRING
Command1.CommandText = "DELETE FROM tbl_listing WHERE property_id = " & strID
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
set Command1 = Nothing
end if
Next
Response.Write "OK Done, one moment!"
%>
<html>
<head>
<title>Update/Delete</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="refresh" content="1;URL=listing_ok.asp">
</head>
<body bgcolor="#FFFFFF" text="#000000">
</body>
</html>
What can I add to both pages to get it to get the name of file in a certain field, go to that path on the server and delete it from the system? This would have to be done allowing for the deletion of multiple files and a code that does not time out if it can't find the file. A file exists script say.
Thanks for reading any of that if you did.
Cheers
---------------------
David Behan - bmor.com
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/property.asp" -->
<%
Response.Buffer = True
Dim iCount
iCount = Request.Form("Count"
Dim strID, strCheck
Dim strSQL
Dim iLoop
For iLoop = 0 to iCount
strCheck = Request(iLoop & ".Check"
strID = Request(iLoop & ".ID"
if strCheck = "Remove" then
set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_property_STRING
Command1.CommandText = "DELETE FROM tbl_listing WHERE property_id = " & strID
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
set Command1 = Nothing
end if
Next
Response.Write "OK Done, one moment!"
%>
<html>
<head>
<title>Update/Delete</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="refresh" content="1;URL=listing_ok.asp">
</head>
<body bgcolor="#FFFFFF" text="#000000">
</body>
</html>
What can I add to both pages to get it to get the name of file in a certain field, go to that path on the server and delete it from the system? This would have to be done allowing for the deletion of multiple files and a code that does not time out if it can't find the file. A file exists script say.
Thanks for reading any of that if you did.
Cheers
---------------------
David Behan - bmor.com