displaying random products

Results 1 to 2 of 2

Thread: displaying random products

  1. #1
    Join Date
    Dec 1969

    Default displaying random products

    I am trying to display 3 featured products on a page from an Application array. I am using the following:<BR><BR>SET Featured = objConn.Execute( strSQL )<BR> IF NOT Featured.EOF THEN<BR> featuredArray = Featured.GetRows()<BR> Featured.Close<BR> END IF<BR> &#039; Add the Array To Application Variable<BR> Application.Lock<BR> Application( "Featured" ) = featuredArray<BR> Application.UnLock<BR> ELSE<BR> featuredArray = Application( "Featured" ) <BR> END IF<BR> <BR> &#039; Display Featured Products<BR> topFeatured = UBOUND( featuredArray, 2 ) + 1<BR> &#039;Response.Write topFeatured & " = top <BR>"<BR> skip = topFeatured / numFeatured<BR> skip = Round(skip)<BR> &#039;Response.Write skip & " = skip<BR>" &#039;<BR> IF topFeatured &#060;= numFeatured THEN skip = 1<BR> &#039;iCount=2<BR> <BR> Dim product1, product2, product3 <BR> icount = 0<BR> <BR> FOR i = 0 TO topFeatured - 1 STEP skip<BR> offset = RND * skip<BR> &#039;Response.Write offset & " = offset<BR>"<BR> IF icount = 0 THEN<BR> product1 = featuredArray(0, i + offset )<BR> &#039;Response.Write "p1 = " & product1<BR> ELSEIF icount = 1 THEN<BR> product2 = featuredArray(0, i + offset )<BR> &#039;Response.Write "p2 = " & product2<BR> ELSEIF icount = 2 THEN<BR> &#039;IF featuredArray(0, i + offset ) &#062;= 5.5 THEN<BR> IF featuredArray(0, i + offset ) THEN<BR> &#039;product3 = featuredArray(0, (i + offset - 1))<BR> &#039;ELSE<BR> product3 = featuredArray(0, i + offset )<BR> &#039;END IF<BR> If product3 = product2 OR product3 = product1 THEN<BR> icount = 1<BR> END IF<BR> Response.Write "p3 = " & product3<BR> END IF<BR> icount =icount + 1<BR> &#039; = featuredArray(0, i + offset )<BR> &#039;Response.write productArray( 0, i ) & "<BR>"<BR> NEXT<BR><BR>The problem I face is that on occasion I am receiving a subscript out of range. Now I gather that this is the offset pushing the selection beyond the products in the array. There are currently 7 in there of which I have to pick 3. Because it is not a straight forward loop and display I am trying to store the item id&#039;s into variables and then query the db for the info I need at the appropriate points on the page.<BR>Is there any way I can modify this so that I can display random products from the array without getting a subscript out of range? I tried limiting the i variable to 5.5 so that the addition of offset wouldn&#039;t happen but it didnt work the way I thought it would.<BR><BR>Any help or advice appreciated. <BR><BR>Lloyd

  2. #2
    Join Date
    Dec 1969

    Default There's something in the FAQs...

    ...that explains how to display records randomly. You should be able to adapt that to your needs.<BR><BR>Oliver.

Posting Permissions

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