gpt4 book ai didi

javascript - 如何用php获取更多标签

转载 作者:行者123 更新时间:2023-12-03 11:22:55 26 4
gpt4 key购买 nike

我正在尝试将多个系列绘制到 fllotchart 中。我成功获取了 1 个标签,但我一直坚持使用 PHP 获取更多标签并编码为 json。

$connection = mysql_connect($server,$user,$password);
$db = mysql_select_db($database,$connection);

$query = "SELECT SC,SR FROM high";
$result = mysql_query($query);

while($row = mysql_fetch_assoc($result))
{
$int = $row['SR'];
$join = intval($int);
$int2 = $row['SC'];
$join2 = intval($int2);
$dataset1[] = array($join2,$join);
}

$final = json_encode($dataset1);
echo $final;

结果

[[1,3],[2,20],[3,30],[4,10],[5,4],[6,40],[7,67],[8,100],[9,5],[10,11]] 

将 JSON 解析为 Javascript

$.ajax({
dataType:'json', /*to avoid calling JSON.parse(data) in your callback function*/
url: 'chart-data.php',
success: function (data) {
console.log(data);//as mentioned in comments
//1.either call plot again
/*calling plot as seen in your code - start*/

var d1 = data;/* JSON.parse(data) */
$.plot($("#placeholder"),
[{
label: "SCR",
data: d1,
},
/*{
label: "SCR",
data: d1,
},*/
],

关注{标签:“SCR”,数据:d1,},

问题:如何将 JSON 数据解析为 JS:

[ { label: "Foo", data: [ [10, 1], [17, -14], [30, 5] ] },
{ label: "Bar", data: [ [11, 13], [19, 11], [30, -7] ] }
]

我只是想使用数组:

$s= array('label'=> "aaaa",
'data'=> $final);
print_r($s);

并得到结果

Array ( [label] => aaaa [data] => [[1,3],[2,20],[3,30],[4,10],[5,4],[6,40],[7,67],[8,100],[9,5],[10,11]] ) 

最佳答案

先创建数组,然后再用 PHP 对其进行编码,如下所示:

$dataset = array("label" => "FOO/BAR", "data" => array(/* Your `data` array */));

还将所有label/data值附加到dataset变量,最后对其进行编码和回显

关于javascript - 如何用php获取更多标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27033440/

26 4 0