dongzhang1839 2012-04-13 06:12
浏览 121
已采纳

将值从php数组传输到jquery

Array $data2 is used for making charts, it contains product names of my company. I want to assign the values in $data2 i.e product names to jquery array 'categories' instead of places listed in the code below...?

<script type="text/javascript">
 $(function () {
 var chart;
 $(document).ready(function() {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'column',
            margin: [ 50, 50, 100, 80]
        },
        title: {
            text: 'Product Selling Report'
        },


  <?php

  $sql="select productid,count(productid)as num from orderdetails group by productid order by num desc";
$res=mysql_query($sql);
$i=0;
   while($arr=mysql_fetch_array($res))
    {
    $rep=$arr['productid'];
    $sql2="select * from product where productid='$rep'";
    $res2=mysql_query($sql2);
    $arr2=mysql_fetch_array($res2);
    $data2[$i]=$arr2['productname'];
    $i=$i+1;
    }

     ?>
        xAxis: 
            categories: [
                'Tokyo',
                'Jakarta',
                'New York',
                'Seoul',
                'Manila',
                'Mumbai',
                'Sao Paulo',
                'Mexico City',
                'Buenos Aires',
                'Guangzhou',
                'Shenzhen',
                'Istanbul'
            ],
      },
      });
  });
   </script>
  • 写回答

3条回答 默认 最新

  • duanguoyin7008 2012-04-13 06:20
    关注
    <script type="text/javascript">
     $(function () {
     var chart;
     $(document).ready(function() {
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'column',
                margin: [ 50, 50, 100, 80]
            },
            title: {
                text: 'Product Selling Report'
            },
            xAxis: 
                categories: [
    
      <?php
    
      $sql="select productid,count(productid)as num from orderdetails group by productid order by num desc";
    $res=mysql_query($sql);
    $i=0;
       while($arr=mysql_fetch_array($res, MYSQL_ASSOC))
        {
        $rep=$arr['productid'];
        $sql2="select * from product where productid='$rep'";
        $res2=mysql_query($sql2);
        $arr2=mysql_fetch_array($res2, MYSQL_ASSOC);
        echo "'".$arr2['productname']."',
    ";
        }
    
         ?>
                ],
          },
          });
      });
       </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog