gpt4 book ai didi

javascript - 谷歌 JavaScript 表

转载 作者:行者123 更新时间:2023-11-29 08:12:45 26 4
gpt4 key购买 nike

可以让这个脚本获取 MySQL 数据吗?有人可以告诉我吗?

这个脚本来自google chars,table ...我尝试让这个脚本获取MySQL数据并显示在表中。

<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {packages:['table']});
google.setOnLoadCallback(drawTable);
function drawTable() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('number', 'Salary');
data.addColumn('boolean', 'Full Time Employee');
data.addRows([
['Mike', {v: 10000, f: '$10,000'}, true],
['Jim', {v:8000, f: '$8,000'}, false],
['Alice', {v: 12500, f: '$12,500'}, true],
['Bob', {v: 7000, f: '$7,000'}, true]
]);

var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: true});
}
</script>
</head>

<body>
<div id='table_div'></div>
</body>
</html>

最佳答案

只需用这样的值填充你的 php 数组

$array = array(
array(
array('01', array('v' => 10000, 'f' => '$10,000'), 'Mike'),
...
array('12', array('v' => 12500, 'f' => '$12,200'), 'Mike'),
)
);

然后在 HTML 代码中写入:

/* code starts here ... */
function drawTable() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'ID');
data.addColumn('number', 'Salariu');
data.addColumn('string', 'Name');
data.addRows(<?php echo json_encode($array) ?>);

var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: true});
}

/* rest of code */

更新

您已经更新了源代码,并且 addRows 方法参数格式已更改,这就是您应该如何填充 php 数组(删除全局数组);

$array = array(
array('01', array('v' => 10000, 'f' => '$10,000'), 'Mike'),
...
array('12', array('v' => 12500, 'f' => '$12,200'), 'Mike'),
);

UPDATE 2帮助mysql数据检索

$array = array();
$result = mysql_query('SELECT f1, f2, f3, f4 FROM some_table');
while($row = mysql_fetch_assoc($result)) {
$array[] = array($row['f1'], array('v' => $row['f2'], 'f' => $row['f3']), $row['f4']);
}

//您的数组现已填满

希望对你有帮助

关于javascript - 谷歌 JavaScript 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21264186/

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