0

Hi I'm working in Google Orgchart and I am confuse how can I build this kind of format in my server side using php.

[
          [{v:'Mike', f:'Mike<div style="color:red; font-style:italic">President</div>'}, '', 'The President'],
          [{v:'Jim', f:'Jim<div style="color:red; font-style:italic">Vice President<div>'}, 'Mike', 'VP'],
          ['Alice', 'Mike', ''],
          ['Bob', 'Jim', 'Bob Sponge'],
          ['Carol', 'Bob', '']
        ]

so that I can put it on my client side to add it on my data.addRows(); like this in there example.

data.addRows([
          [{v:'Mike', f:'Mike<div style="color:red; font-style:italic">President</div>'}, '', 'The President'],
          [{v:'Jim', f:'Jim<div style="color:red; font-style:italic">Vice President<div>'}, 'Mike', 'VP'],
          ['Alice', 'Mike', ''],
          ['Bob', 'Jim', 'Bob Sponge'],
          ['Carol', 'Bob', '']
        ]);

google orgchart

EDIT: ADD SOME DATA

for example I have 3 columns in my mytable,

pcol  lcol   rcol
1       2     3

2       4      5

this is how i do in php to make it json

try{

      $cmd = $this->connection->prepare('SELECT pcol,lcol,rcol from mytbl');
      $cmd->execute();
      $records = $cmd->fetchAll(PDO::FETCH_ASSOC);

      return json_encode($records);


  }catch(){}

the reponse of my ajax is this.

 [{"pcol":"2","lcol":"4","rcol":"5"},{"pcol":"1","lcol":"2","rcol":"3"}]

and it's not working did not display the chart...because of the format.and I would like to know how can I achieve format having v and f.

something like this.

[{v:'2', f:'2'}, '1']

EDIT: looping the result and building the format

 foreach($records as $row) {
      $rowdata[]= '{v:'.$row['lcol'].',f:}'.$row['pcol'];

  }


  $return_data = array($rowdata);



  return json_encode($return_data);

but still it's not working. I'm having difficulties in fomatting the data. here is the output not working.

[["{v:4,f:}2","{v:2,f:}0"]]

Thank you in advance.

ashTon
  • 1,101
  • 4
  • 14
  • 23

0 Answers0