PDA

View Full Version : Database Checkboxes


jeremywatco
11-25-2002, 10:22 PM
I'm stuck. Lets say I have a table that contains 3 fields, ID, Groupname, GroupMembers. This table is always growing, so the values are not static. I want a page so that we can manage these groups. What I was thinking is having an ASP page generate a page that has a username and a checkbox next to it. The page will have many checkboxes on it for all the users. How can I create a page to detect how many checkboxes were created and how many are checked and then update the table. In this example lets just say checking a user addes them to the table (group).

Now I know how to generate the checkboxes, but how do I process this page?

Mhtml
11-26-2002, 01:09 AM
Well looping through the database to get your values and then putting a checkbox next to all the values is easy, you would do it a little like this.


Set conn = Server.CreateObject("Adodb.Connection")
Set rs = Server.CreateObject("Adodb.Recordset")

SqlGetData = "SELECT * FROM Table_Name"
rs.Open SqlGetData, conn
do while not rs.eof
response.Write("<input type=checkbox name=UserName value="&rs("Id")&">")
Response.Write(rs("Username"&"<br>")
Next

That will loop through the data and pu a checkbox next to each name and it's value is the Id.

Now have on another page or the same page..

Set conn = Server.CreateObject("Adodb.Connection")
Set rs = Server.CreateObject("Adodb.Recordset")

SqlInsertData = "INSERT INTO Group (UserName) VALUES ('"&request.Form("UserName")"')"

for each x in request.form
conn.execute(SqlInsertData)
loop


That will loop through all the checked values adding into the database as a name and the id which would be an auto number...I think, I'm not at home so I can't test it.