|
-
Mar 24th, 2002, 03:51 PM
#1
Thread Starter
Fanatic Member
a different deleting question...
hi,
i am doing a delete records page.
the first page (asp) pulls all the users out of a database(access).
they are formated in html w/ a checkbox next to them.
the user selects all the checkbox's and hits the 'delete' button(a form button)
this calls the next page which will delete the users that were selected on page one.
sounds simple enough eh?
my problem is, i don't know how to 'grab' the users on page two.
because i never know how many users are on page one, i have to give the check box's a name like
name="chkBox" & i
where i is variable that gets increased everytime the loop is run
i thought i could have a hidden field that is associated with the checkbox and the user.
so it might look like this
<input type="hidden" value="<%=user%>" name="hidBox" & i>
(or something, that syntax might be allittle off but the idea is, it would have the same name as the check box and the value would be the same as the user)
on page two i was trying to do something like this
dim user
user = request("hidBox")
only i have to add the number to this so i can grab all of them
but i only want the ones that have been selected.
if that explanation doesn't make sense, please tell me and i will try and re-explain it.
basicly, i want to do what hotmail does kinda, where you can select a bunch of records using checkbox's and then delete those records from the database.
thanks for any suggestions!
-
Mar 24th, 2002, 04:08 PM
#2
Hyperactive Member
I'm a little confused by the post however I think I understand what you are trying to do. Instead of naming the checkboxes i couldn't you name them with a unique ID for the record being deleted? This way you would know which record to delete.
Or you could keep the i method. Store the the total number of records in your hidden field. Then when you go to the next page loop for all the records. Check if the checkbox is selected. If selected, delete the record.
-
Mar 24th, 2002, 04:28 PM
#3
Thread Starter
Fanatic Member
yea, what i'm doing now is assigning the value of the checkbox to the ID field from the database.
then when the check box is selected i will get back the number of the checkbox that is associated with the name and id from the database.
only i'm still having trouble.
this is what i have now on page
<input type="checkbox" value="<%=(id)%>" name="chkBox">
on page two i am trying to grab the information like this
dim strName
strName=request.form("chkBox")
i thought it would create a string w/ the values of the selected check box's.
but instead it does nothing.....
the information is being passed because i can see it in the query string. but for some reason it isn't being grabed by the request.form
any more suggestions?
thanks!
-
Mar 24th, 2002, 04:43 PM
#4
You are using the wrong approach, and making it harder. This is how i do it.
Lets say all the users have UserId as a unique identifier.
Now the simplest way to do it is use a control array, by this i mean you name all the check boxes as the same.
eg
page 1.asp
VB Code:
do while not rs.eof
response.write rs("Username") & vbtab & rs("Location") & "<input type=checkbox name=UserId value=" & rs("UserId") & ">Delete<br>"
rs.move next
loop
Now in page 2
you can simply get the selected item by saying
VB Code:
dim uid
uid=request.form("UserId")
if isarray(uid) then
uid=split(uid, ",")
for i=0 to ubound (uid)
sql="Delete From User Where UserId=" & uid(i)
conn.execute(sql)
next
else
'user have only selected one item
sql="delete from user where userid=" & uid
conn.execute(sql)
end if
Hope this helps, sorry about the raw coding, just put it together here, might have errors.
Last edited by Danial; Mar 24th, 2002 at 05:20 PM.
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Mar 24th, 2002, 04:45 PM
#5
Hyperactive Member
I think I see the problem now. Checkboxes only have two values, checked and unchecked. What you should do is name each checkbox by the unique ID. Then you can check each checkbox on the next page by ID. If it is selected, then you know to delete that record.
-
Mar 24th, 2002, 04:47 PM
#6
Originally posted by pnj
dim strName
strName=request.form("chkBox")
i thought it would create a string w/ the values of the selected check box's.
but instead it does nothing.....
the information is being passed because i can see it in the query string. but for some reason it isn't being grabed by the request.form
any more suggestions?
thanks!
You say you can see the querystring that means you are using get method, in that you should use
strName=request.querystring("chkBox")
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Mar 24th, 2002, 04:58 PM
#7
Thread Starter
Fanatic Member
yea i'm using
request("chkBox") and that seems to be working.
Danial, i like your idea. i'll give it a try. it looks alot easier than what i was trying.
thanks again.
-
Mar 24th, 2002, 05:48 PM
#8
Thread Starter
Fanatic Member
the isarray thing doesn't seem to be working....
i am using personal web server on windows 98
is it a asp 3. thing?
thanks
-
Mar 24th, 2002, 05:49 PM
#9
Hyperactive Member
I like my idea the best..
-
Mar 24th, 2002, 06:06 PM
#10
Originally posted by DKCK
I like my idea the best..
Sorry DKCK, you got the wrong idea, I am sure your idea works too, there is alwasy more then way of doing things. i mearly suggested an alternative which i have used frequently and also pnj asked if there was any other way of doing it. No offence was meant to you. And i certainly dont intend to get into argument on whose code is best as i am here to help people and get help not to prove anything . No hard feelings
Pnj i am not sure about what asp version supports IsArray(), you could use instr function to check if the user selected more then one item.
Are you sure the error is with Isarray, post your code here if possible.
Danial
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Mar 24th, 2002, 06:25 PM
#11
Thread Starter
Fanatic Member
well, i assume the problem is with the isarray thing because when i put a response.write line of code into the for next loop (just to see if that part of the code ever runs) it doesn't write anything to the browser.
so i tried to comment out the if then statement and just run the isarray function.....just to test it.
here is what my code looks like now
uid=request.form("chkAddressID")
Response.Write uid
'if isarray(uid) then
uid=split(uid, ",")
for i=0 to ubound (uid)
sql="Delete From email Where ID=" & uid
conn.execute(sql)
Response.Write "in the array<br>"
Response.Write sql
next
'else
'user have only selected one item
' sql="delete from email where userid=" & uid
' conn.execute(sql)
' Response.Write "not in the array"
'end if
'********
you can see i commented out a few lines. that is just for testing purposes.
what i get in the browser is the first response.write uid
then i get the "in the array" section writen out.
if i uncomment out the lines, it allways jumps to the ELSE part of the statement.
another funny thing is, the response.write sql doesn't write anything to the browser....
thanks again!
-
Mar 24th, 2002, 07:03 PM
#12
PNJ,
the first code i posted had few erros in it, i dont think the error is with IsArray
here is the clean version of it
VB Code:
<%
uid=request.form("chkAddressID")
if isarray(uid) then
uid=split(uid, ",")
for i=0 to ubound (uid)
sql="Delete From email Where ID=" & uid(i)
Response.Write sql & "<br>"
next
else
sql="delete from email where userid=" & uid
Response.Write sql
end if
%>
This code is the same but it doesnt use IsArray
VB Code:
<%
uid=request.form("chkAddressID")
if instr(1, uid, ",") then
uid=split(uid, ",")
for i=0 to ubound (uid)
sql="Delete From email Where ID=" & uid (i)
Response.Write sql & "<br>"
next
else
sql="delete from email where userid=" & uid
Response.Write sql
end if
%>
Test them out now.
Hope this helps.
Danial
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Mar 24th, 2002, 07:05 PM
#13
Thread Starter
Fanatic Member
ok, here is where i am now.
it seems as if the split function does not work.
if i do this
uid= request.form("id")
uid=split(uid, ",")
Response.Write uid
it prints out the same thing as uid. i meen, it is still delimitaed by commas.
so when it is printed out it looks something like this.
1,3,8,9
with those numbers being the checkbox's on page one that were selected.
so my sql statement allways looks like this
delete email where ID = 1,3,8,9
instead of looking like this
delete emai where ID= 1
then on the next loop it would look like
delete email where ID= 3
etc....
does that make sense?
another strange thing is, if i write the sql inside the for next loop.
it doesn't seem to work.
in my last post i said i couldn't get it to write to the screen using response.write sql
but if i take the sql line out of the for/next loop. it will write to the screen. only then it won't add the next ID number.....
sorrry if that makes no sense. i have made to progress on this thing that should be very easy to get to work.....
-
Mar 24th, 2002, 07:18 PM
#14
Try out my the cleaned up code.
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Mar 24th, 2002, 07:53 PM
#15
Thread Starter
Fanatic Member
nice!
yea, that works great.
thanks!!
now to get the actual DELETE function to work.....
i have a connection open to the database so all i should have to do is put
conn.execute(sql) inside the for/next loop right?
i'll give it a try...
thanks again!
-
Mar 24th, 2002, 08:02 PM
#16
Re: nice!
Originally posted by pnj
yea, that works great.
thanks!!
now to get the actual DELETE function to work.....
i have a connection open to the database so all i should have to do is put
conn.execute(sql) inside the for/next loop right?
i'll give it a try...
thanks again!
you are welcome. sorry about the first post, i just thougt you need a quick ans, so i posted some pseducode without test.
Yep it should be inside the loop.
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Mar 24th, 2002, 11:11 PM
#17
Hyperactive Member
Actually I like his answer better...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|