This topic is locked

How to pass master page key to the detail page Gantt

PHPRunner General questions
Lance Spurgeon author

I am using google gantt charts on project tasks on my todo list.
The have built a the xml builder and use ajax api to prefil the gantt. The issue I have is to pass the master page id to the xml builder.

This is the custom php page building the XML file

include ("../../include/dbcommon.php");

$qry ="SELECT t1.taskname AS `Task ID`, t1.taskname AS `Task Name`, t3.`name` AS Resource, t1.schedstart AS `Start Date`, t1.schedend AS `End Date`, t1.esthours AS Duration, t1.tercentcomplete AS `Percent Complete`, t1.dependenton AS Dependencies FROM todocards_tasks AS t1 INNER" .
" JOIN todocards AS t2 ON t1.todocards_id = INNER JOIN todocategories AS t3 ON t2.categoryid = WHERE t1.todocards_id= ".$_REQUEST["masterkey1"]."";
$result = mysqli_query($conn,$qry);

$table = array();
$table['cols'] = array(
//Labels for the chart, these represent the column titles
array('id' => '', 'label' => 'Task ID', 'type' => 'string'),
array('id' => '', 'label' => 'Task Name', 'type' => 'string'),
array('id' => '', 'label' => 'Resource', 'type' => 'string'),
array('id' => '', 'label' => 'Start Date', 'type' => 'date'),
array('id' => '', 'label' => 'End Date', 'type' => 'date'),
array('id' => '', 'label' => 'Duration', 'type' => 'number'),
array('id' => '', 'label' => 'Percent Complete', 'type' => 'number'),
array('id' => '', 'label' => 'Dependencies', 'type' => 'string')

$rows = array();
foreach($result as $row){

$taskid = str_replace(' ', '', $row['Task ID']);
$dates = date_create($row['Start Date']);
$date_s = "Date(".date_format($dates, 'Y').", ".((int) date_format($dates, 'm') - 1).", ".date_format($dates, 'd').")";
//$date_s = "Date(".date_format($dates, 'Y').", 0, ".date_format($dates, 'd').")";

$datee = date_create($row['End Date']);
$date_e = "Date(".date_format($datee, 'Y').", ".((int) date_format($datee, 'm') - 1).", ".date_format($datee, 'd').")";
//$date_e = "Date(".date_format($datee, 'Y').", 0, ".date_format($datee, 'd').")";

$daystomili = "daysToMilliseconds(".$row['Duration'].")";
$dependencies = str_replace(' ', '', $row['Dependencies']);

$temp = array();

$temp[] = array('v' => (string) $taskid);
$temp[] = array('v' => (string) $row['Task Name']);
$temp[] = array('v' => (string) $row['Resource']);

$format = 'Y, m, d';
$temp[] = array('v' => (string) $date_s);
$temp[] = array('v' => (string) $date_e);
$temp[] = array('v' => (string) $daystomili);
$temp[] = array('v' => (string) $row['Percent Complete']);
$temp[] = array('v' => (string) $dependencies);
$rows[] = array('c' => $temp);


$table['rows'] = $rows;

$jsonTable = json_encode($table, true);
print $jsonTable;

//echo '<pre>';
//echo json_encode($table, JSON_PRETTY_PRINT);
//echo '</pre>';

This is the ajax page in the javascript onload.
google.charts.load('current', {'packages':['gantt']});

function daysToMilliseconds(days) {
return days 24 60 60 1000;

function drawChart() {

var jsonData = $.ajax({
url: "include/chart_graph/getDataTodoTasks.php?masterkey1="+pageid,
async: false

// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);

var options = {
height: 200,
gantt: {
criticalPathEnabled: false,
innerGridHorizLine: {
stroke: '#f4f5f8',
fontName: '"Roboto", sans-serif',
strokeWidth: 2
percentEnabled: true,
innerGridTrack: {fill: '#ffffff'},
innerGridDarkTrack: {fill: '#f4f5f8'}

var chart = new google.visualization.Gantt(document.getElementById('chart_allcamps_div'));
chart.draw(data, options);
This is the typical url that the Gantt is on

I want to change the query in my custom page to change depending on the mastertable record value to filter this Grantt

I am clearly not doing something right here, any help appreciated

Lance Spurgeon author 6/9/2021

Oh and this part is the Google Graph API, that I have on the before display


admin 6/9/2021

I think the following line is incorrect, pageid is not defined anywhere:
url: "include/chart_graph/getDataTodoTasks.php?masterkey1="+pageid,

Your scheme looks too complicated, you are passing something from PHP to Javascript and then back to PHP. Simply save this value in the session variable and use it in PHP code.

fhumanes 6/12/2021


Just as inspiration. See this article: