我从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);
请你能帮我解决这个问题吗?
答案 0 :(得分: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);
答案 1 :(得分:0)
其工作精细
$ json = Array();
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);