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 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    Ipswich
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    taking data from a database and putting it into an array

    I have a table called "Broadcast" and would like to take the contents of the "Title" column and put it into an array. This array will then be displayed in a javascript scroll bar which I already have working.
    My problem is I don't know how to get the data from the database into the Array using ASP.

    Can anyone help?

    thanks Pete

    P.S the javascript just uses a straightforward array at the moment to display the messages.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    ok, this is JSCRIPT, which probaly isn't much help, but...


    Code:
    <@LANGUAGE=JSCRIPT%>
    
    <%
    //get a recordset populated. I assume you have one already
    
    %>
    
    <html>
    
    <head>
    
    <script language="JavaScript">
    
    var myArray=new Array();
    
    
    <%
    var counter=0
    while (!myRecordSet.EOF){
    %>
    
    myArray[counter]="<%=rs.Fields("myColumnName")%>";
    
    <%
    counter++
    rs.MoveNext;
    }
    %>
    
    </script>
    
    </head>
    
    <body>
    
    
    <script language="JavaScript">
    
    for(i=0;i<myArray.length;i++){
     document.write(myArray[i]);
    }
    </script>
    
    </body></html>

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    At the appropriate place where you define the javascript array loop through the recordset and have it response.write the values to fill the array. Think of it as having the server side ASP code writing the client side javascript code.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Roy's suggestion is a good way to go. I do that all the time!
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #5
    New Coder
    Join Date
    Aug 2002
    Location
    Ipswich
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cheers, that worked fine.

    thanks for the help

    Pete


  •  

    Posting Permissions

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