Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8889501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:16:40+00:00 2026-06-14T22:16:40+00:00

I am trying to dynamicaly generate data in json for jQuery gantt chart. I

  • 0

I am trying to dynamicaly generate data in json for jQuery gantt chart. I know PHP but am totally green with JavaScript. I have read dozen of solutions on how dynamicaly add data to json, and tried few dozens of combinations and nothing. Here is the json format:

var data = [{
    name: "Sprint 0",
    desc: "Analysis",
    values: [{
        from: "/Date(1320192000000)/",
        to: "/Date(1322401600000)/",
        label: "Requirement Gathering", 
        customClass: "ganttRed"
        }]
    },{
    name: " ",
    desc: "Scoping",
    values: [{
        from: "/Date(1322611200000)/",
        to: "/Date(1323302400000)/",
        label: "Scoping", 
        customClass: "ganttRed"
        }]
    }, <!-- Somoe more data-->

      }];

now I have all data in php db result. Here it goes:

$rows=$db->fetchAllRows($result);
$rowsNum=count($rows);

And this is how I wanted to create json out of it:

var data='';
<?php foreach ($rows as $row){ ?>
data['name']="<?php echo $row['name'];?>";
data['desc']="<?php echo $row['desc'];?>";
data['values'] = {"from" : "/Date(<?php echo $row['from'];?>)/", "to" : "/Date(<?php echo $row['to'];?>)/", "label" : "<?php echo $row['label'];?>", "customClass" : "ganttOrange"};
}

However this does not work. I have tried without loop and replacing php variables with plain text just to check, but it did not work either. Displays chart without added items. If I add new item by adding it to the list of values, it works. So there is no problem with the Gantt itself or paths. Based on all above I assume the problem is with adding plain data to json. Can anyone please help me to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:16:42+00:00Added an answer on June 14, 2026 at 10:16 pm

    First of all you’re adding properties to string instead of building object. If you really want to do that this way:

     var data = [], row;
     <?php foreach ($rows as $row) : ?>
         row = {};
         row.name ="<?php echo $row['name'];?>";
         row.desc ="<?php echo $row['desc'];?>";
         row.values = {"from" : "/Date(<?php echo $row['from'];?>)/", "to" : "/Date(<?php echo $row['to'];?>)/", "label" : "<?php echo $row['label'];?>", "customClass" : "ganttOrange"};
         data.push(row);
     <?php endforeach; ?>
    

    Anyway it is unsafe (and result is normal JS code, not proper JSON object – but as you’re assigning it to variable then I suppose it does not have to be in strict JSON format)

    Better approach would be to build data structure in PHP and use json_encode function to generate JSON data for JavaScript:

     <?php
     $data = array();
     foreach ($rows as $row) {
          $data[] = array(
              'name'   => $row['name'],
              'desc'   => $row['desc'],
              'values' => array(array(
                  'from'        => '/Date('.$row['from'].'>)/', 
                  'to'          => '/Date('.$row['to'].')/',
                  'label'       => $row['label'], 
                  'customClass' => 'ganttOrange',
              ))
          );
     }
     ?>
     var data = <?php echo json_encode($data); ?>;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Passing JavaScript Array To PHP Through JQuery $.ajax I'm trying to pass
I am trying to have my interface dynamically generate a customized button when I
I'm new to JQuery and don't have a huge background in Javascript, either -
I am trying to send data from dynamicly generated cheboxes(when ticked) to my php
I am trying to generate HTML which will display the data from XML through
I'm trying to parse returned information that can have a variable amount of data
I'm trying to write an html/javascript set (to be interpreted in PHP) that allows
I am trying to use a textarea form entry which I have some javascript
I am trying to dynamically generate a list/dropdown using JQuery's .ajax method. Following is
I am trying to dynamically fetch the data from a PhP module, load it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.