Array Problem

1. Junior Member
Join Date
Dec 1969
Posts
17

## Array Problem

Hi All,<BR><BR>I&#039;m havin a problem displaying a number of products and images on a page. There are a pre-determined number of products returned by my SQL statement (always a set of 6, but which get updated frequently) which might make this a bit easier?<BR><BR>Basically, my plan is to place each of the 6 products into an array and then physically call in the relevent array positions in turn to display the product details on screen.<BR><BR>But I can&#039;t figure out how to move through the returned recordset AND loop through the contents of the array. I&#039;ve read the FAQ about GetRows() but I&#039;m not sure I can apply it to this because the products are arranged 2 rows by 3 columns which makes it awkward to put into a loop in the HTML.<BR><BR>Here&#039;s what I&#039;ve got:<BR><BR>&#060;%<BR>&#039;select the store products that are on special offer<BR>SQL2 = "Select * from product where storeID = "<BR>SQL2 = SQL2 & storeno<BR>SQL2 = SQL2 & "AND specialOffer = True"<BR>set RSprod = Conn.Execute(SQL2)<BR><BR>&#039;place the special offer product details in a series of arrays<BR>Dim prodidArray(6)<BR>Dim prodnameArray(6)<BR>Dim prodpriceArray(6)<BR>Dim prodcatArray(6)<BR><BR>FOR I = 1 to 6<BR>prodidArray(I) = RSprod("prodID")<BR>NEXT<BR><BR>FOR N = 1 to 6<BR>prodnameArray(N) = RSprod("prodName")<BR>NEXT<BR><BR>FOR M = 1 to 6<BR>prodpriceArray(M) = RSprod("prodPrice")<BR>NEXT<BR><BR>FOR P = 1 to 6<BR>prodcatArray(P) = RSprod("prodCat")<BR>NEXT<BR>%&#062;<BR><BR>Then I want to call in the physical array position for each of the 6 products in the HTML - <BR><BR>e.g. <BR><BR>Name of Product No. 1 = response.write(prodnameArray(1))<BR>Name of Product No. 2 = response.write(prodnameArray(2))<BR>Name of Product No. 3 = response.write(prodnameArray(3))<BR><BR>etc..<BR>< BR>But all this does is give me 6 instances of the same product because it&#039;s not moving through the recordset! How can I do this?<BR><BR>Thanks in advance for help!<BR><BR>Cheers,<BR><BR>Chris.

2. Senior Member
Join Date
Dec 1969
Posts
2,854

## RE: Array Problem

&#060;% <BR>&#039;select the store products that are on special offer <BR>SQL2 = "Select * from product where storeID = " <BR>SQL2 = SQL2 & storeno <BR>SQL2 = SQL2 & "AND specialOffer = True" <BR>set RSprod = Conn.Execute(SQL2) <BR><BR>DO While Not RSprod.EOF<BR>&#039;place the special offer product details in a series of arrays <BR>Dim prodidArray(6) <BR>Dim prodnameArray(6) <BR>Dim prodpriceArray(6) <BR>Dim prodcatArray(6) <BR><BR>FOR I = 1 to 6 <BR>prodidArray(I) = RSprod("prodID") <BR>NEXT <BR><BR>FOR N = 1 to 6 <BR>prodnameArray(N) = RSprod("prodName") <BR>NEXT <BR><BR>FOR M = 1 to 6 <BR>prodpriceArray(M) = RSprod("prodPrice") <BR>NEXT <BR><BR>FOR P = 1 to 6 <BR>prodcatArray(P) = RSprod("prodCat") <BR>NEXT <BR>RSprod.movenext<BR>loop<BR><BR>%&#062;

3. Senior Member
Join Date
Dec 1969
Posts
2,854

## oops

Sorry, not thinking straight!<BR><BR><BR>&#039;place the special offer product details in a series of arrays <BR>Dim prodidArray(6) <BR>Dim prodnameArray(6) <BR>Dim prodpriceArray(6) <BR>Dim prodcatArray(6) <BR>Dim I<BR>i = 0<BR>DO While Not RSprod.EOF<BR>prodidArray(I) = RSprod("prodID") <BR>prodnameArray(I) = RSprod("prodName") <BR>prodpriceArray(I) = RSprod("prodPrice") <BR>prodcatArray(I) = RSprod("prodCat") <BR><BR>I =I+1<BR>RSprod.movenext<BR>loop<BR>

4. Junior Member
Join Date
Dec 1969
Posts
17

## Nice One!!

Genius mate!!!!!!<BR><BR>Cheers! :)

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## YUCK

What&#039;s the point of that???<BR><BR>Why does it matter if you get 4 individual 1D arrays or one 2D array?<BR><BR>&#060;%<BR>&#039; make sure you get fields *explicitly*<BR>SQL = "SELECT prodID, prodName, prodPrice, prodCat FROM ..."<BR><BR>CONST COL_ID = 0<BR>CONST COL_NAME = 1<BR>CONST COL_PRICE = 2<BR>CONST COL_CAT = 3<BR><BR>Set RS = conn.Execute( SQL )<BR><BR>infoArray = RS.GetRows()<BR>RS.Close<BR><BR>&#039; and now you can refer to a given column/row easily<BR>&#039; where you would have done<BR>&#039; prodidArray(row)<BR>&#039; with the single arrays, you now simply use<BR>Response.Write( COL_ID, row )<BR><BR>%&#062;<BR><BR>This will be *MUCH* more efficient.<BR><BR>Having said that...ehh...if this is on a lightly used website, then who cares about the performance?<BR><BR>

#### Posting Permissions

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