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>

&lt;%@LANGUAGE="VBSCRIPT"%&gt;
&lt;!--#include file="../Connections/property.asp" --&gt;
&lt;%
Dim RsProperty__MMColParam
RsProperty__MMColParam = "1"
if (Request.QueryString("type" &lt;&gt; "" then RsProperty__MMColParam = Request.QueryString("type"
%&gt;
&lt;%
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
%&gt;
&lt;%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
RsProperty_numRows = RsProperty_numRows + Repeat1__numRows
%&gt;
&lt;%
' *** 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 &lt; 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 &lt;&gt; -1) Then
If (RsProperty_first &gt; RsProperty_total) Then RsProperty_first = RsProperty_total
If (RsProperty_last &gt; RsProperty_total) Then RsProperty_last = RsProperty_total
If (RsProperty_numRows &gt; RsProperty_total) Then RsProperty_numRows = RsProperty_total
End If
%&gt;
&lt;%
' *** 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 &gt; 0) Then
RsProperty.MoveFirst
Else
RsProperty.Requery
End If

' set the number of rows displayed on this page
If (RsProperty_numRows &lt; 0 Or RsProperty_numRows &gt; 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 &gt; RsProperty_total) Then RsProperty_first = RsProperty_total
If (RsProperty_last &gt; RsProperty_total) Then RsProperty_last = RsProperty_total

End If
%&gt;
&lt;%
' *** 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 &lt;&gt; "" 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 &lt;&gt; "" Then MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
if (MM_keepURL &lt;&gt; "" Then MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
if (MM_keepForm &lt;&gt; "" 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 &lt;&gt; "" Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%&gt;

<font color=red><b>Repeat Region and Form for Delete</font id=red></b>


&lt;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"&gt;
&lt;% If Not RsProperty.EOF Or Not RsProperty.BOF Then %&gt;
&lt;p&gt;&lt;span class="medbold"&gt;Total:&lt;/span&gt; &lt;%=(RsProperty_total)%&gt; Properties&lt;/p&gt;
&lt;table border="0" cellpadding="0" cellspacing="0" class="mednormal" width="100%"&gt;
&lt;% Dim iCount
iCount = 1
%&gt;
&lt;%
While ((Repeat1__numRows &lt;&gt; 0) AND (NOT RsProperty.EOF))
%&gt;
&lt;tr &lt;% if repeat1__numrows mod 2 = 0 then %&gt;bgcolor="#EFEFEF"&lt;% End If %&gt; bgcolor="#DFDFDF"&gt;
&lt;td align="default" width="30"&gt;
&lt;div align="center"&gt;
&lt;input type="checkbox" name="&lt;%= (iCount & ".Check" %&gt;" value="Remove"&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td align="default"&gt;
&lt;% If RsProperty.Fields.Item("onsite".Value = ("Yes" Then 'script %&gt;
&lt;span class="medbold"&gt;&lt;%=(RsProperty.Fields.Item("address".Value)%&gt;&lt;/span&gt;
&lt;% End If ' end If RsProperty.Fields.Item("onsite".Value = ("Yes" script %&gt;
&lt;% If RsProperty.Fields.Item("onsite".Value = ("No" Then 'script %&gt;
&lt;span class="mednormal"&gt;&lt;%=(RsProperty.Fields.Item("address".Value)%&gt;&lt;/span&gt;
&lt;% End If ' end If RsProperty.Fields.Item("onsite".Value = ("No" script %&gt;
&lt;input type="hidden" name="&lt;%= (iCount & ".ID" %&gt;" value="&lt;%=(RsProperty.Fields.Item("property_id".Value)%&gt;"&gt;
&lt;/td&gt;
&lt;td align="default" width="80"&gt;
&lt;div align="center"&gt;&lt;%=(RsProperty.Fields.Item("status".Value)%&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;td align="default" width="130"&gt;
&lt;div align="right"&gt;&lt;a href="listing_edit.asp?&lt;%= MM_keepURL & MM_joinChar(MM_keepURL) & "property_id=" & RsProperty.Fields.Item("property_id".Value %&gt;"&gt;&lt;img src="images/edit.gif" width="18" height="16" alt="Edit this property's details" border="0"&gt;&lt;/a&gt;
&lt;a href="listing_picsm.asp?&lt;%= MM_keepURL & MM_joinChar(MM_keepURL) & "property_id=" & RsProperty.Fields.Item("property_id".Value %&gt;"&gt;&lt;img src="images/small.gif" width="18" height="16" border="0" alt="Modify or delete the small image for this property"&gt;&lt;/a&gt;
&lt;a href="listing_piclg.asp?&lt;%= MM_keepURL & MM_joinChar(MM_keepURL) & "property_id=" & RsProperty.Fields.Item("property_id".Value %&gt;"&gt;&lt;img src="images/large.gif" width="18" height="16" border="0" alt="Modify or delete the large image for this property"&gt;&lt;/a&gt;
&lt;a href="listing_reset.asp?&lt;%= MM_keepURL & MM_joinChar(MM_keepURL) & "property_id=" & RsProperty.Fields.Item("property_id".Value %&gt;"&gt;&lt;img src="images/reset.gif" width="18" height="16" alt="Reset the pictures associated with this property" border="0"&gt;&lt;/a&gt;
&lt;a href="print.asp?&lt;%= MM_keepURL & MM_joinChar(MM_keepURL) & "property_id=" & RsProperty.Fields.Item("property_id".Value %&gt;" target="_blank"&gt;&lt;img src="images/print.gif" width="18" height="16" alt="Print this property's details on to your headed paper" border="0"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
RsProperty.MoveNext()
iCount = iCount + 1
Wend
%&gt;
&lt;/table&gt;
&lt;p&gt;&lt;span class="medboldalt"&gt;NOTE&lt;/span&gt;&lt;span class="medbold"&gt;:&lt;/span&gt;
The &lt;span class="medbold"&gt;addresses&lt;/span&gt; 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.&lt;/p&gt;
&lt;p&gt;
&lt;input type="submit" name="Submit" value="Delete Selected Properties"&gt;
&lt;input type="hidden" name="Count" value="&lt;%= iCount - 1 %&gt;"&gt;
&lt;/p&gt;
&lt;% End If ' end Not RsProperty.EOF Or NOT RsProperty.BOF %&gt;
&lt;/form&gt;


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:

&lt;%@LANGUAGE="VBSCRIPT"%&gt;
&lt;!--#include file="../Connections/property.asp" --&gt;
&lt;%
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!"
%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Update/Delete&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="refresh" content="1;URL=listing_ok.asp"&gt;
&lt;/head&gt;

&lt;body bgcolor="#FFFFFF" text="#000000"&gt;
&lt;/body&gt;
&lt;/html&gt;



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

Reply to this topic