I’m not sure what I’m doing wrong. Does ids have to be sequential? Is the child tag required? Can you go three levels down?
If I used the commented code on the bottom instead of my json it works.
Thanks,
David
Target Array (gets converted to json)
0 =>
array (
‘id’ => ‘2013-ZZ-000158’,
‘text’ => ‘2013-ZZ-000158 - MY CASE TITLE’,
),
1 =>
array (
‘item’ =>
array (
0 =>
array (
‘id’ => ‘2013-ZZ-000158-David Test’,
‘text’ => ‘David Test’,
),
1 =>
array (
‘item’ =>
array (
0 =>
array (
‘id’ => ‘2013-ZZ-000158|David Test|pleadings@test.com’,
‘text’ => 'pleadings@test.com’,
),
1 =>
array (
‘id’ => ‘2013-CA-000158|David Test|sleitten@test.com’,
‘text’ => 'sleitten@test.com’,
),
2 =>
array (
‘id’ => ‘2013-ZZ-000158|David Test|swinig@test.com’,
‘text’ => 'swinig@test.com’,
),
3 =>
array (
‘id’ => ‘2013-ZZ-000158|David Test|william@test.com’,
‘text’ => 'william@test.com’,
),
),
),
),
),
)
Export routine -
function get_event_emails_json($event_id=0) {
$rows = $this->get_event_emails($event_id);
if(isset($_GET["id"]))
$id=$_GET["id"];
else $id=0;
$myarr = array();
$last_c = $last_m = $last_e = '';
$loop_c = $loop_m = $loop_e = 0;
foreach ($rows as $row) {
extract($row);
if ($last_c != $case_num) {
$myarr[$loop_c]['id'] = $case_num;
$myarr[$loop_c]['text'] = $case_num . ' - ' . $case_style;
//echo json_encode($myarr[$loop_c]);
$last_c = $case_num;
$loop_c++;
$loop_m = 0;
}
if ($last_m != $motion) {
$last_m = $motion;
$myarr[$loop_c]['item'][$loop_m]['id'] = $case_num . '-' . $motion;
$myarr[$loop_c]['item'][$loop_m]['text'] = $motion;
//echo json_encode($myarr[$loop_m]['item']);
$loop_m++;
$loop_e = 0;
}
if ($last_e != $email_addr) {
$last_e = $email_addr;
$myarr[$loop_c]['item'][$loop_m]['item'][$loop_e]['id'] =
$case_num . '|' . $motion . '|' . $email_addr;
$myarr[$loop_c]['item'][$loop_m]['item'][$loop_e]['text'] = $email_addr;
//echo json_encode($myarr[$loop_m]['item'][$loop_e]);
$loop_e++;
}
}
echo json_encode($myarr);
logit($myarr);
/*
// works
echo "{id:'".$id."', item:[\n";
for ($i=0; $i <5 ; $i++) {
if ($i!=0) echo "," ;
echo "{id:'".$i.'-'.$id."', text:'level 1-".$i."-".$id."', child:'1' }\n";
}
echo "]}\n";
*/
}