PDA

View Full Version : Multiple database changes


Esona
05-01-2003, 07:36 PM
Hey.. I'm working on a script that requires multiple database entries to be changed all at once, how can I do that?

The story line is the user selects a bunch of database entries he/she wants to delete, then clicks the delete button, the browser then goes to the delete page and deleted the selected IDs..
it looks like this when I display the selected ones:
Response.Write Selected
1023777937, 1051593108 (etc)

Thanks

raf
05-01-2003, 08:19 PM
You just need to build the sql statement on the fly, uising a loop that checks if the checkbow was clicked (then value is 1).

some code that might be inspiring. The checkboxes name must be the records ID (the form is also dynamically build).:

sql = "delete from thetable where "
sql = replace(sql,"thetable",request.form("Table"))

For each box in request.form
if request.form(box) = "1" then
if row = 1 then
sql = sql + "(Id=" + box + ")"
else
sql = sql + " OR (Id=" + box + ")"
end if
row = row + 1
end if
next

if row = 1 then
response.write ("<font color='red'>No records selected to be deleted.</font>")
response.write("<br><br><a href='javascript:history.back();'>Back</a>")

else

%><!--#include file='yourdbconnection.inc'-->
<%
dim numberdel
conname.Execute sql,numberdel

(you can also use where ID in (...) clause in the statement)

By the looks of it, you gave alle chackboxes the same name, so you'll need to use a splitfunction and then build the statement with a loop.

Esona
05-01-2003, 08:28 PM
I guess I should've mentioned I'm using Microsoft Access databases..

raf
05-01-2003, 08:42 PM
I guess I should've mentioned I'm using Microsoft Access databases..

Meaning ? :confused: This works with MsAccess. It actually comes from a sort of web-admin tool i wrote for access db's.