Ask a Question related to ASP Database, Design and Development.
-
Laphan #1
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
-
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... -
Nesting Arrays within arrays.
How do i nest an array inside another array? something like array(i).aray2(j); Can I do that? -
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... -
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... -
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... -
Kindler Chase #2
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
-
Laphan #3
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



Reply With Quote

