Reputation: 923
I need to get data in javascript array using asp. How to get data and put it in this format in javascript array . This example is of php .
<script>var chartdata=[{"values":[<?php $conn =mysql_connect("host","root","pass") or die ("we couldn't connect!");mysql_select_db("test");$rs = mysql_query("SELECT x1 FROM table") or die(mysql_error());while($row = mysql_fetch_array($rs)){echo $row['x'].',';}?>],}];</script>
Upvotes: 0
Views: 299
Reputation: 4663
I'm assuming you know about adodb connection and recordset objects (if you don't there are plenty of tutorials out there), and that you've created one of each called conn
and rs
.
In Classic ASP I'd do something like this
<% Dim myarraystring, sql
sql = "SELECT x1 FROM table"
myarraystring = ""
rs.open sql,conn
Do While Not rs.eof
myarraystring = myarraystring & rs("x") & ","
rs.movenext
Loop
rs.close %>
<script>var chartdata=[{"values":[<%= myarraystring %>],}];</script>
Your connection string would depend on what driver you're using. There's a good resource here for connecting to MySQL with classic asp http://www.connectionstrings.com/mysql/
Upvotes: 1