homepage Welcome to WebmasterWorld Guest from 54.166.159.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / WebmasterWorld / New To Web Development
Forum Library, Charter, Moderators: brotherhood of lan & mack

New To Web Development Forum

    
Multiple Row Update - with Radio Buttons in Classic ASP
Multiple Row Update - with Radio Buttons in Classic ASP
buck1107

10+ Year Member



 
Msg#: 3864403 posted 5:16 pm on Mar 6, 2009 (gmt 0)

I currently am looking for a method to update multiple rows in a db (using classic ASP) from a form which submits data to those rows using radio buttons. I've done something similar in the multiple update 'style' with checkboxes, although it looks like radio buttons might be a quite different design.
Would I still use an array in the design?

Many thanks for any help or suggestions.
Louis

 

brotherhood of LAN

WebmasterWorld Administrator brotherhood_of_lan us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 3864403 posted 7:41 pm on Mar 9, 2009 (gmt 0)

Did you have any luck sorting this out buck?

buck1107

10+ Year Member



 
Msg#: 3864403 posted 7:55 pm on Mar 9, 2009 (gmt 0)

Hi,
No, I'm still looking for a way to do this.
Thanks,
Louis

brotherhood of LAN

WebmasterWorld Administrator brotherhood_of_lan us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 3864403 posted 7:00 am on Mar 13, 2009 (gmt 0)

Hi buck,

Hopefully someone can chip is with a more knowledgeable reply as I don't use ASP and have very limited knowledge of its syntax.

You could use an array if you've been using one before. For these kind of situations I'd have something like formfield[rowid] as the formfield name and the rowid also as the value.

Your radiobox form submission would be an array of rowid values which ASP acts upon. Have you tried testing the form submission and seeing what the POST variables look like to ASP?

buck1107

10+ Year Member



 
Msg#: 3864403 posted 11:12 pm on Mar 13, 2009 (gmt 0)

I'm kind of a newbie at ASP - how can I test the request.form post? I was thinking also of doing a replace of the first part of the radio button id (leaving the number) and somehow loading the sequence of button id's into an array. I'm not sure how to do that, but that seems like it might work.
Thanks again for your help - much appreciated!

brotherhood of LAN

WebmasterWorld Administrator brotherhood_of_lan us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 3864403 posted 7:48 pm on Mar 15, 2009 (gmt 0)

A PHP equivalent of getting to "see" the form variables after the form submission would be

<?php print_r($_POST); ?>
<input type="text name="test" value="12345" />
<input type="submit" />

Afte clicking submit, the PHP variable $_POST['test'] would have the variable 12345.

I assume you could submit your form and look at how ASP is storing your variables in a similar way.

buck1107

10+ Year Member



 
Msg#: 3864403 posted 1:39 pm on Mar 19, 2009 (gmt 0)

Thanks for the information!
I've started doing response.write's on my page and am currently returning arrays of the form results.
Will keep you posted.

Thanks
Louis

buck1107

10+ Year Member



 
Msg#: 3864403 posted 8:11 pm on May 4, 2009 (gmt 0)

I finally arrived at a solution! Many thanks to you all for helping on this. I've only included the processing code - the form is further down on the page and posts to the same page.
While this script does all I had hoped, it is quite slow...does anyone see somthing(s) that might be streamlined for faster operations? It's quite heavy on the array end, but I figured that an array would be lighter on processing than continually calling the db. Thanks for your input! :)

Kind Regards,
Louis
----------------- :)


<%if request.Form("frmSubmit") = "Update" then

today = now
if request("strComplete_" & i) ="true" then
strComplete = 1
else
strComplete = 0
end if

'////make Array from "FormComplete" form elements

For each item in Request.Form

If Left(item,12) = "strComplete_" Then
iFormComplete = item & (request.form(item)) 'get form item name and value
iFormComplete = replace(iFormComplete, "strComplete_", "") 'remove "strComplete_" from each form item
strFormComplete = strFormComplete & iFormComplete & "," 'add comma after each
End If

Next

If len(strFormComplete)>0 then
strFormComplete = left(strFormComplete, (len(strFormComplete) -1)) 'remove last comma
arrFormComplete = split(strFormComplete, ",") 'make array
End If

'///////////////////////////////////////////////////
'////begin - make recordset
strOrder = "AMS_ContentOverview.CourseID"

strSQL = "SELECT AMS_CourseCategory.CourseCatDesc, AMS_ContentOverview.CourseID, AMS_ContentOverview.Complete "_
&"FROM AMS_ContentOverview INNER JOIN "_
&"AMS_Courses ON AMS_ContentOverview.CourseID = AMS_Courses.CourseID INNER JOIN "_
&"AMS_CourseCategory ON AMS_Courses.CourseCatID = AMS_CourseCategory.CourseCatID "_
&"ORDER BY " & strOrder

'Create a Recordset
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.cursorlocation = 3
objRS.Open strSQL, objConnection

dim arrVarFieldNames, arrDbVals
arrVarFieldNames = Array("CourseID", "Complete")

arrDbVals= objRS.GetRows(,,arrVarFieldNames)

dim iRowLoop, iColLoop, zRowLoop, strChange, tempDbValsCase
'////loop through db values and compare to form values in inner loop
for iRowLoop = 0 to ubound(arrDbVals, 2)

'////loop through form values for comparison to db values in outer loop
for zRowLoop = 0 to ubound(arrFormComplete)

tempDbValsCase = lcase(trim(arrDbVals(1, iRowLoop)))

'////perform comparison of db value to form value
if (mid(trim(arrFormComplete(zRowLoop)),1,8) = trim(arrDbVals(0, iRowLoop))) AND (mid(trim(arrFormComplete(zRowLoop)),9) <> tempDbValsCase) then

'////make string of changed value id's
dim strFormAllVals
strFormAllVals = arrFormComplete(zRowLoop)
strChange = strChange & strFormAllVals & ","

end if

next

next

'//////////make array of changed value id's
If len(strChange)>0 then
'////trim off the trailing ","
strChange = left(strChange, (len(strChange) -1))
arrValsChange = split(strChange, ",")

'/////
dim strValsComplete, strValsInComplete
for i = 0 to ubound(arrValsChange)

dim strTempValsComplete, strTempValsInComplete
if mid(trim(arrValsChange(i)), 9) = "true" then
strTempValsComplete = trim(arrValsChange(i))
strTempValsComplete = replace(strTempValsComplete, "strComplete_", "")
strTempValsComplete = replace(strTempValsComplete, mid(strTempValsComplete, 9), "")

strValsComplete = strValsComplete & strTempValsComplete & ","

elseif mid(trim(arrValsChange(i)), 9) = "false" then
strTempValsInComplete = trim(arrValsChange(i))
strTempValsInComplete = replace(strTempValsInComplete, "strComplete_", "")
strTempValsInComplete = replace(strTempValsInComplete, mid(strTempValsInComplete, 9), "")

strValsInComplete = strValsInComplete & strTempValsInComplete & ","
end if
next

'/////
If len(strValsComplete)>0 then
strValsComplete = left(strValsComplete, (len(strValsComplete) -1))
arrValsComplete = split(strValsComplete, ",")
End If

If len(strValsInComplete)>0 then
strValsInComplete = left(strValsInComplete, (len(strValsInComplete) -1))
arrValsInComplete = split(strValsInComplete, ",")
End If

'/////

If ((len(strValsComplete)>0) or (len(strValsInComplete>0))) then

If len(strValsComplete)>0 then
strSql = ""
table="AMS_ContentOverview"
strSql = strSql & "UPDATE " & table & " SET Complete = 1, LastUpdate = '"& today & "' WHERE "

for i = 0 to ubound(arrValsComplete)
if i = 0 then
strSql = strSql & "CourseID = "& arrValsComplete(i)
else
'only add the " OR " if this is not the first value
strSql = strSql & " OR CourseID = "& arrValsComplete(i)
end if
next

%>
<!--#include virtual="/common/db/QryDbCommand.asp"-->
<%
End If

'////
If len(strValsInComplete)>0 then
strSql = ""
table="AMS_ContentOverview"
strSql = strSql & "UPDATE " & table & " SET Complete = 0, LastUpdate = '"& today & "' WHERE "

for i = 0 to ubound(arrValsInComplete)
if i = 0 then
strSql = strSql & "CourseID = "& arrValsInComplete(i)
else
'only add the " OR " if this is not the first value
strSql = strSql & " OR CourseID = "& arrValsInComplete(i)
end if
next

%>
<!--#include virtual="/common/db/QryDbCommand.asp"-->

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / New To Web Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved