gpt4 book ai didi

php - 将值从 php 数组传输到 jquery

转载 作者:行者123 更新时间:2023-12-02 19:43:15 25 4
gpt4 key购买 nike

数组$data2用于制作图表,它包含我公司的产品名称。我想将 $data2 中的值(即产品名称)分配给 jquery 数组“类别”,而不是下面代码中列出的位置...?

<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>

最佳答案

<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']."',\n";
}

?>
],
},
});
});
</script>

关于php - 将值从 php 数组传输到 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10136078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com