0

我从 jquery 开始,我正在尝试将数据从 php 文件加载到 jQuery.Gantt ( http://taitems.github.io/jQuery.Gantt/ )。但图表确实加载。

剧本:

        $(".gantt").gantt({
            source: 'gantt_data_json.php',
            navigate: "scroll",
            scale: "weeks",
            maxScale: "months",
            minScale: "days",
            itemsPerPage: 10,
              ....
            });

gantt_data_json.php:

        require_once('libs/common.php');

        $query ="SELECT * from gantt_table";
        $result = mysql_query($query) or die("SQL Error 1: " . mysql_error());
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$gantt[] = array(
'name' =>$row['name'],
'desc' => $row['desc'],
'values' => array(
   'to' => '/Date('.strtotime($row['to']).')/',
   'from' => '/Date('.strtotime($row['from']).')/',
   'desc' =>$row['desc2'],
   'label' => $row['label'],
   'customClass' => 'ganttRed'
  )
  );

          }             
           echo json_encode($gantt);                

请问你能帮我解决这个问题吗?

4

2 回答 2

0

尝试这个:

    $query = "SELECT * from gantt_table";
    $result = mysql_query($query) or die("SQL Error 1: " . mysql_error());
    $gantt = array();

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $data[] = array(
            'name' => $row['name'],
            'desc' => $row['desc'],
            'values' => array(
                array(
                    'from' => '/Date(' . $row['from'] . ')/',
                    'to' => '/Date(' . $row['to'] . ')/',
                    'desc' => $row['desc2'],
                    'label' => $row['label'],
                    'customClass' => 'ganttRed',
                ),
            )
        );

        $gantt[] = $data;
    }
    echo json_encode($gantt); 
于 2013-10-17T08:42:43.093 回答
0

它的工作正常

$json = 数组();

    while ($rs = mysqli_fetch_array($rsPedidos))
    {

        $data[] = array(
        'name' => $rs['projeto'],
        'desc' => $rs["site"],
        $valor[] = array(                
                    'from' => '/Date(' . strtotime($rs["data_inicio_ti"]) . '000)/',
                    'to' => '/Date(' . strtotime($rs["data_fim_ti"]) . '000)/',
                    'desc' => $rs["funcionario"].' / PO:'.$rs["numero_po"].' / R$:'.$rs["valor_po"],//12658580,//1320192000000 1497582000
                    'label' => $rs["servico"],
                    'customClass' => 'ganttRed',
            ),
        'values' =>$valor,
        );

    $json = $data;
   }

    print json_encode($json); 
于 2017-07-26T15:49:53.173 回答