Trying to load data from a php file to jQuery.Gantt

advertisements

I'm starting in jquery, and I am trying to load the data from a php file to the jQuery.Gantt (http://taitems.github.io/jQuery.Gantt/). But the chart does load.

The script:

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

The 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);

Please could you help me to solve this issue?


Try this:

    $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);