Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: Array's

  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Array's

    I beleive what i want to create is an array, but not sure it is so i'm not sure on what to google.

    I have a table

    custid address enabled
    1 bill@test.com 1
    1 bob@test.com 1
    1 dave@test.com 0


    enabled being true false,

    i have a form mail script, that you can give it a whole load of addresses seperated by a comma. SO

    is there any way i can define a variable from the results of my query i.e. with loop?


    i.e. select * from table where cid = '1' and enabled = 1

    so i would have 2 results from that, bill and bob @test.com seperated with a comma so it can be defined as my to list in formmail (brainjar)

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Since you are pulling these from your db server, use the recordset.GetRows() feature.

    It takes your query and pulls the results into an array automatically.

    Here's the usage:
    Code:
    ' Assuming you know how to define and open a connection and recordset
    '
    rs.open "select * from table where cid = '1' and enabled = 1", conn
      if not rs.eof then
        arrResults = rs.GetRows()
        iRowMax = ubound(arrResults,2)
      end if
    rs.close
    '
    for x = 0 to iRowMax
      'loop through your results using arrResults(0,x)
    next
    '
    Erase arrResults
    Just remember that using "SELECT *" is not the best idea. Define which fields you want to see and put them into your SELECT.
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah i can connect to database, i am i wrint in thinking i just need to put

    from = arrResults

    ?

  • #4
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Unfortunately, with GetRows() or any arrays, you can't do just a simple from = array.

    Arrays need to be written out one element at a time.

    If you want comma separated values, then use CONCAT() on your SQL string.

    Code:
    SELECT concat(custid,',',address,',',enabled) 'result' FROM your_table WHERE cid = '1' AND enabled = 1
    Then do a loop or Array pull based on that.
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    as far as i can see, the way to go here is:

    query the db with:
    select address from table where enabled = 1

    then return the results with getrows, this will give the array.

    Now you can make this into a commadelimited string with the join function:

    Dim strAddresses

    strAdresses = Join(arrResults,",")

    Which will join all elements in the array, separating them with the provided string, in this case a comma

    good luck!
    I am the luckiest man in the world

  • #6
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    ... or you could use the Recordset getString() method to do it without all that tedious mucking about with arrays

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    Quote Originally Posted by Spudhead View Post
    ... or you could use the Recordset getString() method to do it without all that tedious mucking about with arrays
    That is a good one spudhead, i did not know this method.
    I am the luckiest man in the world


  •  

    Posting Permissions

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