Best way to do Arrays with my data

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Best way to do Arrays with my data

    Hi Guys

    Thanks to some recent help from you, I managed to work my ASP shop cart page
    so that it puts the DB order data into arrays so that I get the totals I
    want and then re-iterate through these arrays so that I can display the
    actual order lines.

    Only problem is that I think I'm using very infantile/newbie methods for my
    array. Basically I've done this:

    dim arrStockCode(50)
    dim arrStockQty(50)
    dim arrStockPrice(50)
    dim x
    dim z

    x = 0

    Do my Recordset loop til EOF
    arrStockCode(x) = oRSv("CODE")
    arrStockQty(x) = oRSv("QTY")
    arrStockPrice(x) = oRSv("PRICE")
    Loop it

    Do my calcs

    ' === Do another loop to print order lines to HTML page

    For z = 0 to x-1
    <%=arrStockCode(z)%>
    etc...
    Next

    I know the above will work fine, but there are 2 issues:

    1) It will work so long as nobody orders above 51 (0 to 50) product lines.

    2) More importantly I'm creating 6 arrays with 51 (0 to 50) params in each
    when probably only upto 5 params in each array will actually get filled with
    data, as the customer will probably not order more than that.

    Should I be doing these arrays a different way? Is there something that
    allows me to dynamically increase the size of the arrays to the appropriate
    sizes?

    Thanks

    Laphan








    Laphan Guest

  2. Similar Questions and Discussions

    1. Using arrays in a Data model
      Hi, Im really struggling to use Arrays in a DataModel. At the moment I am able to populate a datagrid with my different arrays, into their...
    2. Nesting Arrays within arrays.
      How do i nest an array inside another array? something like array(i).aray2(j); Can I do that?
    3. Linking data, searching data, and format the data file
      I'm sorta new to flash and integrating data and components...I'm usu. an interface designer. I'm trying to link a combo box to a file doesn't...
    4. arrays
      i have an array called ComboProperties i have a text box called property.text a user can enter a value into the text box i need to put all...
    5. Speed of data access in arrays
      Will calling ksort() on an array speed up it's access? For example, I have the array $file_index, which is accessed by a key (the entry id) and...
  3. #2

    Default Re: Best way to do Arrays with my data

    Laphan wrote:
    > Hi Guys
    >
    > Thanks to some recent help from you, I managed to work my ASP shop
    > cart page so that it puts the DB order data into arrays so that I get
    > the totals I want and then re-iterate through these arrays so that I
    > can display the actual order lines.
    >
    > Only problem is that I think I'm using very infantile/newbie methods
    > for my array. Basically I've done this:
    >
    > dim arrStockCode(50)
    > dim arrStockQty(50)
    > dim arrStockPrice(50)
    > dim x
    > dim z
    >
    > x = 0
    >
    > Do my Recordset loop til EOF
    > arrStockCode(x) = oRSv("CODE")
    > arrStockQty(x) = oRSv("QTY")
    > arrStockPrice(x) = oRSv("PRICE")
    > Loop it
    >
    > Do my calcs
    >
    > ' === Do another loop to print order lines to HTML page
    >
    > For z = 0 to x-1
    > <%=arrStockCode(z)%>
    > etc...
    > Next
    >
    > I know the above will work fine, but there are 2 issues:
    >
    > 1) It will work so long as nobody orders above 51 (0 to 50) product
    > lines.
    >
    > 2) More importantly I'm creating 6 arrays with 51 (0 to 50) params in
    > each when probably only upto 5 params in each array will actually get
    > filled with data, as the customer will probably not order more than
    > that.
    >
    > Should I be doing these arrays a different way? Is there something
    > that allows me to dynamically increase the size of the arrays to the
    > appropriate sizes?

    It looks like you may need to re-think how your placing your recordset into
    an array... more specifically, you should be using the getRows method. Here
    are a few links to get you started:
    [url]http://www.learnasp.com/learn/whygetrows.asp[/url]
    [url]http://www.stardeveloper.com/articles/display.html?article=2000080601&page=1[/url]
    [url]http://www.4guysfromrolla.com/webtech/tips/t053100-1.shtml[/url]
    [url]http://www.asp101.com/samples/db_getrows.asp[/url]


    Some sample code:

    <%
    option explicit

    '************************************************* ***
    ' n3_GetRecordsInArray
    ' Purpose: Place a recordset into an array with getRows
    ' Inputs: sqlString: SQL statement to query the DB.
    ' connString: connection string to the DB.
    ' Outputs: An array of values
    ' rsArray(arrayVal,1) = num. columns
    ' rsArary(arrayVal,2) = num. rows
    ' Creator: Kindler Chase - [url]www.nCubed.com[/url]
    ' Date: 10/2003
    '************************************************* *
    Private Function n3_GetRecordsInArray(sqlString, connString)
    Dim rsArray, conn
    Dim sql, rs
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open connString
    Set rs = conn.Execute(sqlString)
    If Not rs.EOF And Not rs.BOF Then rsArray = rs.getRows()
    Set rs = Nothing
    conn.close()
    Set conn = Nothing
    n3_GetRecordsInArray = rsArray
    End Function 'n3_GetRecordsInArray


    Dim rsStocks 'recordset for the array
    Dim sql 'sql query for the getRows function
    Dim connString 'a connection string to the DB
    Dim i 'a counter
    Dim strStocks 'variable for the stocks to write out

    'constants to identify the db column in the array
    ;(number is always equal to position called in the sql query)

    Const conStockCode = 0
    Const conStockQty = 1
    Const conStockPrice = 2

    sql = "SELECT StockCode, StockQty, StockPrice FROM tblStocks ORDER BY
    StockCode"
    connString = "String To Your Database"
    strStocks = ""

    rsStocks = GetRecordsInArray(sql, connString)

    If IsArray(rsStocks) Then
    For i = Lbound(rsStocks,2) To Ubound(rsStocks,2)
    strStocks = strStocks & rsStocks(conStockCode, i) & vbNewLine
    strStocks = strStocks & rsStocks(conStockQty, i) & vbNewLine
    strStocks = strStocks & rsStocks(conStockPrice, i) & vbNewLine
    Next
    Else 'no array was returned
    strStocks = "No Stock Results were Returned."
    End If

    Response.Write(strStocks)

    %>

    --

    kindler chase
    [url]http://www.ncubed.com[/url]
    Home of SuperInvoice's PlayGround

    [url]news://news.ncubed.com/support[/url]
    n3 Support Group


    Kindler Chase Guest

  4. #3

    Default Re: Best way to do Arrays with my data

    Many thanks Kindler

    Going to try and get my head round this.

    Rgds

    Laphan


    Kindler Chase <billyboy@DELETE_ME_roubaixinteractive.com> wrote in message
    news:#QcpEvz$DHA.684@tk2msftngp13.phx.gbl...
    Laphan wrote:
    > Hi Guys
    >
    > Thanks to some recent help from you, I managed to work my ASP shop
    > cart page so that it puts the DB order data into arrays so that I get
    > the totals I want and then re-iterate through these arrays so that I
    > can display the actual order lines.
    >
    > Only problem is that I think I'm using very infantile/newbie methods
    > for my array. Basically I've done this:
    >
    > dim arrStockCode(50)
    > dim arrStockQty(50)
    > dim arrStockPrice(50)
    > dim x
    > dim z
    >
    > x = 0
    >
    > Do my Recordset loop til EOF
    > arrStockCode(x) = oRSv("CODE")
    > arrStockQty(x) = oRSv("QTY")
    > arrStockPrice(x) = oRSv("PRICE")
    > Loop it
    >
    > Do my calcs
    >
    > ' === Do another loop to print order lines to HTML page
    >
    > For z = 0 to x-1
    > <%=arrStockCode(z)%>
    > etc...
    > Next
    >
    > I know the above will work fine, but there are 2 issues:
    >
    > 1) It will work so long as nobody orders above 51 (0 to 50) product
    > lines.
    >
    > 2) More importantly I'm creating 6 arrays with 51 (0 to 50) params in
    > each when probably only upto 5 params in each array will actually get
    > filled with data, as the customer will probably not order more than
    > that.
    >
    > Should I be doing these arrays a different way? Is there something
    > that allows me to dynamically increase the size of the arrays to the
    > appropriate sizes?

    It looks like you may need to re-think how your placing your recordset into
    an array... more specifically, you should be using the getRows method. Here
    are a few links to get you started:
    [url]http://www.learnasp.com/learn/whygetrows.asp[/url]
    [url]http://www.stardeveloper.com/articles/display.html?article=2000080601&page=1[/url]
    [url]http://www.4guysfromrolla.com/webtech/tips/t053100-1.shtml[/url]
    [url]http://www.asp101.com/samples/db_getrows.asp[/url]


    Some sample code:

    <%
    option explicit

    '************************************************* ***
    ' n3_GetRecordsInArray
    ' Purpose: Place a recordset into an array with getRows
    ' Inputs: sqlString: SQL statement to query the DB.
    ' connString: connection string to the DB.
    ' Outputs: An array of values
    ' rsArray(arrayVal,1) = num. columns
    ' rsArary(arrayVal,2) = num. rows
    ' Creator: Kindler Chase - [url]www.nCubed.com[/url]
    ' Date: 10/2003
    '************************************************* *
    Private Function n3_GetRecordsInArray(sqlString, connString)
    Dim rsArray, conn
    Dim sql, rs
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open connString
    Set rs = conn.Execute(sqlString)
    If Not rs.EOF And Not rs.BOF Then rsArray = rs.getRows()
    Set rs = Nothing
    conn.close()
    Set conn = Nothing
    n3_GetRecordsInArray = rsArray
    End Function 'n3_GetRecordsInArray


    Dim rsStocks 'recordset for the array
    Dim sql 'sql query for the getRows function
    Dim connString 'a connection string to the DB
    Dim i 'a counter
    Dim strStocks 'variable for the stocks to write out

    'constants to identify the db column in the array
    ;(number is always equal to position called in the sql query)

    Const conStockCode = 0
    Const conStockQty = 1
    Const conStockPrice = 2

    sql = "SELECT StockCode, StockQty, StockPrice FROM tblStocks ORDER BY
    StockCode"
    connString = "String To Your Database"
    strStocks = ""

    rsStocks = GetRecordsInArray(sql, connString)

    If IsArray(rsStocks) Then
    For i = Lbound(rsStocks,2) To Ubound(rsStocks,2)
    strStocks = strStocks & rsStocks(conStockCode, i) & vbNewLine
    strStocks = strStocks & rsStocks(conStockQty, i) & vbNewLine
    strStocks = strStocks & rsStocks(conStockPrice, i) & vbNewLine
    Next
    Else 'no array was returned
    strStocks = "No Stock Results were Returned."
    End If

    Response.Write(strStocks)

    %>

    --

    kindler chase
    [url]http://www.ncubed.com[/url]
    Home of SuperInvoice's PlayGround

    [url]news://news.ncubed.com/support[/url]
    n3 Support Group




    Laphan Guest

Posting Permissions

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

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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139