Array Multiple records

This is a discussion on "Array Multiple records" within the Classic ASP section. This forum, and the thread "Array Multiple records are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jan 11th, 2006, 00:07
New Member
Join Date: Jan 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Question Array Multiple records

Hello-

I have a form where I have mutiple lines of the same thing. Users will input a type of equipment the ID# and other minute data. Instead of creating a table and column for every line, I would like to create a new row for each line the user inputs. However, i am not sure how i can force the array to know which line goes with what data? You can see an example here:
http://www.ecinsurance.com/test/equipment.htm

any help would be appreciated. I have the following code for simple array inputs. Changes and suggestions to make what i need work would be helpful

if Request.Form <> "" then
CNumber = CNumber
office_name= Request.form("office_name")
Office_ID = Request.form("Office_ID")
Office_purchase = Request.form("Office_purchase")
Office_date = Request.form("Office_date")
Office_cost = Request.form("Office_cost")
Office_condition = Request.form("Office_condition")

MyList = Request.Form("ListID")
myArray = split(MyList,",")
For i = 0 to uBound(myArray)
strSQL = strSQL & "INSERT INTO MyTable (Cnumber, Office_Name, Office_ID, Office_Purchase, Office_Date, Office_Cost, Office_Condition) VALUES (" & CNumber & "," & myArray(i) & ");"
NEXT
GetFromDatabase strSQL
Response.Redirect"newpage.asp"
end if
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jan 11th, 2006, 18:34
Reputable Member
Join Date: Sep 2003
Location: USA
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Array Multiple records

I couldn't find anything that guarenteed that office_date(i) would necessarily correlate to Office_cost(i) when I did something like this. Not to say that it isn't true, but I never found documentation one way or another.

So I created form fields office_date0, office_Date1.... and a hidden field called count
Then on the processing end I looped the form from 0 to count-1 inserting request.form("office_[variable]" & i)

It's clunky, but totally reliable and reasonably readable.

Let me know if you'ld like to see code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jan 11th, 2006, 22:41
New Member
Join Date: Jan 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Array Multiple records

Thank you for the response. It shows you know exactly what i am talking about. Some code would be helpful! Thanks again!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jan 12th, 2006, 14:25
Reputable Member
Join Date: Sep 2003
Location: USA
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Array Multiple records

Well this was for books, but I think you'll get the idea...

on the html page:
Code: Select all
<form  name="ContribEdit" method="post" action="BookProcessing.asp">
    <fieldset>
        <legend>Edit Contributors</legend>
        <table>
            <tr>
                <th align="left">Contributor Name</th>
                <th align="left">Type</th>
                <th align="center">Display order</th>
                <th align="center">Remove?</th>
            </tr>
            <% for j = 0 to thisBook.getContributorCount-1 %>
            <tr>
                <td><%= getValue(thisBook.getContributor(j).getContribID, "contributor" ) %> <input type = "hidden" class="hidden" alt="Contributor <%response.write j+1%>" name = "OldID<%= j %>" value="<%= thisBook.getContributor(j).getUniqueID%>"><input type = "hidden" class="hidden" name="Contrib<%= j %>" value="<%= thisBook.getContributor(j).getContribID%>">
                </td>
                <td><%= DDBuilder(array(thisBook.getContributor(j).getContribType, j), "contribtypes" ) %> </td>
                <td><input type = "Text" name = "Ordinal<%=j%>" size = "5" value="<%= thisBook.getContributor(j).getContribNumber %>"></td>
                <td class="center"><input type = "Checkbox" name = "Delete<%=j%>" value="Delete<%= thisBook.getContributor(j).getContribNumber %>"></td>
            </tr>
            <% next %>
        </table>
            <input type = "hidden" class="hidden" name = "Process" value="BookEditContribs">
            <input type = "hidden" class="hidden" name = "ContribCount" value="<%= thisBook.getContributorCount%>">
            <input type = "hidden" class="hidden" name = "isbnNoHyph" value="<%= thisBook.getIsbnNoHyph%>">
            <input type="Submit" name="submit" Value="Submit">
    </fieldset>
</form>
Then on the receiving end...
Code: Select all
                for i = 0 to getArrayData("ContribCount") - 1
        '            if testing then response.write "<p>" & join(array(getArrayData("ISBNNoHyph"), getArrayData("Contrib" & i), getArrayData("Ordinal" & i), getArrayData("ctypes" & i), getArrayData("OldID" & i)), ": " )
                    if getArrayData("Delete" & i) = "Delete" & i then
                        succeed = succeed AND DeleteBookContrib (getArrayData("ISBNNoHyph"), getArrayData("Contrib" & i))
                    else
                        succeed = succeed AND EditBookContrib (getArrayData("ISBNNoHyph"), getArrayData("Contrib" & i), getArrayData("Ordinal" & i), getArrayData("ctypes" & i), getArrayData("OldID" & i))
                    end if
                next
Where:
Code: Select all
    function DeleteBookContrib (ISBNNoHyph , ContribID)
    'delete a contributor for a book.
        dim return
        return=false
        if len(ISBNNoHyph )>0 and isnumeric(contribID) then
            BookSQL = join(array("DELETE TblBookContributorID FROM TblBookContributor WHERE ", _
                                                        "ISBNNoHyph=", quoteme(ISBNNoHyph), "AND", _
                                                        "ContributorID=", ContribID), " ")

            if testing then     response.write "<P>" & BookSQL
            conn.execute BookSQL
            return = true
        end if
        DeleteBookContrib = return
    end function
and
Code: Select all
    function EditBookContrib (ISBNNoHyph, ContribID, Ordinal, TypeID, OldID)
        dim return
        dim  newID
        'edit a book contributor


if testing then response.write "<p>" & join(array( len(ISBNNoHyph ) > 0 ,  isnumeric(contribID) ,  isnumeric(ordinal) ,  isnumeric(typeID) ), ": " )
        return=false
        if len(ISBNNoHyph ) > 0 and isnumeric(contribID) and isnumeric(ordinal) and isnumeric(typeID) then
            newID = join(array(ISBNNoHyph, ContribID, Ordinal, TypeID), ".")
            BookSQL=join(array("UPDATE TblBookContributor SET ", _
                                                        "ContributorID=", ContribID, ", ", _
                                                        "ContributorNumber=", Ordinal, ", ", _
                                                        "TypeID=", TypeID, ", ", _
                                                        "BookContributorID=", quoteme(newID), _
                                                    "WHERE BookContributorID=", quoteme(OldID)), " ")
            if testing then     response.write "<P>" & BookSQL
            conn.execute BookSQL
            return = true
        end if
        EditBookContrib = return
    end function
This is a pretty simple example with only a couple of variables actually being able to be changed on this form, but I think you can get the idea.

(getArrayData is just a funciton to store all of the form in one array so you don't have to know where it comes from because in this application I didn't...)

I also use join(array(list), "[]") a lot to join a series of things instead of item1 & "[]" & item2.... It's cleaner to read.

Let me know if anything else isn't clear...

HTH
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jan 15th, 2006, 21:00
New Member
Join Date: Jan 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up Re: Array Multiple records

This worked great! Thanks for the code and the help!

James F.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jan 16th, 2006, 19:02
New Member
Join Date: Jan 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Re: Array Multiple records

Would you be available for some freelance work? I would need some of that work in the next 2 days if possible.

Thanks
James F.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jan 17th, 2006, 16:44
Reputable Member
Join Date: Sep 2003
Location: USA
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Array Multiple records

I might be interested, but not in the next 2 days. I've got commitments for the next 3 evenings.

Thanks for the offer.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
array, multiple, records

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Select records based on multiple conditions - need help Love2Java Databases 9 Oct 29th, 2007 14:37
Validatwe multiple checkbox with array [] Mochachino JavaScript Forum 0 May 5th, 2007 04:44
Updating multiple records at the same time prob. with script at51178 Classic ASP 11 Feb 1st, 2006 17:56
array unable to check another array so as to be displayed Ozeona Flash & Multimedia Forum 1 Aug 5th, 2005 10:26
Appending multiple records jakyra Classic ASP 0 Sep 8th, 2003 19:33


All times are GMT. The time now is 15:45.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42