Array problems

Results 1 to 3 of 3

Thread: Array problems

  1. #1
    Join Date
    Dec 1969

    Default Array problems

    Hi, I do not no anything about arrays, but I need to use one. I&#039m presenting result from a database, titles of books, from different SQL-strings and I want to make sure that one book will not be shown more than one time. I can not use the DISTINCT in my SQL as it is several strings. So for every SQL string I want to save all the titles in an array and before I present any title I want to make sure it is not allready in the array. And of course if it is not in the array I want to write it out and add it to the array and go along o the next SQL-string.

  2. #2
    Steve Cimino Guest

    Default RE: Array problems

    Bring back your array in sorted data (do it in the database.. you&#039re not going to like VBScript&#039s methods of sorting arrays)<BR><BR>Then, loop through the array checking the next element, if it was = to the previous element.

  3. #3
    Join Date
    Dec 1969

    Default RE: Array problems

    This rough code may help you....<BR><BR>Dim a() <BR>Set conn = Server.CreateObject("ADODB.Connection")<BR>conn.op en (DSN&#060;UID&#060;PWD)<BR>sql = "SELECT * FROM books" & _<BR> Set rs = Server.CreateObject("ADODB.Recordset")<BR> rs.Open sql, conn, 3, 1<BR>for i = 1 to rs.recordcount<BR><BR>FOR Q = 1 TO UBOUND(A)<BR>if rs("bookname") &#060;&#062; a(q) then<BR>(HERE DISPLAY THE BOOK SINCE THIS IS NOT IN ARRAY AND AGAIN ADD TO ARRAY FOR FUTURE CHECKING)<BR>response.write(rs("bookname")<BR>(HER E FIRST WE HAVE NOT DECLARED DIMENSION OF ARRAY,BUT AS WE OPEN RECORDSET WE WILL INCREASE DIMENSION OF ARRAY .. SO ARRAY WILL BE SIZE OF RECORDSET, ALSO WE WILL PRESERVE ORIGINAL VALUES)<BR>(WRITE A CODE TO CHECK IF THIS BOOK IS ALREADY THERE)<BR>redim preserve a(ubound+1)<BR>a(ubound+1) = rs("bookname")(AADING BOOKNAME in the end)<BR>end if<BR>NEXT<BR>next<BR> rs.Close<BR> conn.close<BR><BR>this is not a perfect code.. but may be served as guide line<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