Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用php获得更多标签_Javascript_Php_Json - Fatal编程技术网

Javascript 如何使用php获得更多标签

Javascript 如何使用php获得更多标签,javascript,php,json,Javascript,Php,Json,我想把多个系列画进弗洛特哈特。我成功地获得了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

我想把多个系列画进弗洛特哈特。我成功地获得了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 */));

并将所有的
标签/数据
值附加到
数据集
变量中,最后编码并回显它

是否可以“标签”和“数据”没有字符串?“”string character=“”(数组的)这些键可以包含所有类型的变量,这是什么意思?我不明白…当我尝试你的建议时,这个结果是{“label”:“foo”,“data”:如何删除标签和数据之间的字符串字符?只需{label:“foo”,data:arraydata}Non!!!当你想创建数组时,数组索引必须是数字或字符串(关联数组)。如果可能的话,我不知道怎么做