SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamic Record Updating

    Ok..here is the background..

    I am dynamically building a query from an access db to output on a separate page. This is working fine.

    On this page (the query results page), I want to have checkboxes and a text field where the user can input text and select the records to update (by checking the box). Once they select and hit submit, I want to update only the records selected.

    Problem is, I am trying to figure out the most efficient way of doing this...any ideas?




  2. #2
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have one idear...

    Do a RecordCount and pass the value in a hidden field. Then go into a loop (for x = 1 to RecordCount)

    While in the loop, check to see if the checkbox is checked (that's a lot of 'checks' in one sentence) and update the appropriate records.

    hmm.

    [vbs]
    <%
    for x = 1 to RecordCount
    if Request.Form("checkbox") = "true" then
    UPDATE table blah blah
    end if
    %>
    [/vbs]

    Not very efficient..I think. May be I can use the Dictionary Object and store all the variables in there...

  3. #3
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This article maybe what you want.

  4. #4
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,289
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    What I would suggest you do is setup the checkboxes sequentially with the value corresponding to the key of the records you want to update. Then, your code would look something similar to this:

    [vbs]
    Dim MaxRecords, InClause, CheckBox, LoopCnt, strSQL

    MaxRecords = Request.Form("maxcheckboxes") ' Want to specify this on the calling page. If you know it and it'll never change, hardcode it...
    InClause = ""

    For LoopCnt = 1 to MaxRecords
    CheckBox = Request.Form("Checkbox" & LoopCnt)
    if Len(Trim(CheckBox)) > 0 then
    if Len(InClause) > 0 then
    InClause = InClause & ","
    end if
    InClause = InClause & CheckBox ' If Key is an alpha field, you'll need to surround with "'"
    end if
    Next

    strSQL = "UPDATE TABLE " & _
    " SET TextField = '" & Request.Form("UpdateText") & "'" & _
    " WHERE RecordKey IN (" & InClause & ")"
    myConn.Execute (strSql)
    [/vbs]
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  5. #5
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by shane
    This article maybe what you want.
    That is pretty close to what I need! I should be able to work something out if I can ever get my table to update the Yes/No Field!

    Thanks Shane and Dave!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •