dpzff20644 2016-01-18 07:23
浏览 93
已采纳

如何在asp.net中获取数组值(或者asp-classic会更好)

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>
  • 写回答

1条回答 默认 最新

  • dr2898 2016-01-18 13:41
    关注

    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/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?