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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号