0

Here is a piece of my code:

if($all_pages)
  foreach ($all_pages as $page) 
  {
    $all_hokms = $mysqli->query("SELECT * FROM qm_hokm WHERE page_id =   ".$page['page_id']."");
   if($all_hokms)
     foreach ($all_hokms as $hokm) 
     {
      $one_page_ahkams[] = array(
    'hokm_id_inPage' => $hokm['hokm_id_inPage'],
    'type' => $page['type'],
    );
     }
    else
     $one_page_ahkams[] = array();

    $all_pages_data[] = array(
    'page_id' => $page['page_id'],
    'done' => $page['done'],
    'checked' => $page['checked'],
    'ahkams' => array($one_page_ahkams), //Here Is the PROBLEM : (((
    );
}
else
    $all_pages_data[] = array();
echo json_encode($all_pages_data);

As you see, I want to send multidimensial array() in a json format (from server to client), but how can correct the insertion of an array in an other, I mean that I need to add $one_page_ahkams array in $all_pages_data one, any ideas

2 Answers 2

0
$one_page_ahkams = array();

$all_pages_data[] = array(
'page_id' => $page['page_id'],
'done' => $page['done'],
'checked' => $page['checked'],
'ahkams' => array($one_page_ahkams);//this comma (,) causes the problem i guess**
);

An other way to do it :

$all_pages_data[] = array(
'page_id' => $page['page_id'],
'done' => $page['done'],
'checked' => $page['checked'],
'ahkams' => array(['one_page_ahkams']=>$one_page_ahkams);
);
3
  • i spoke about comma(,) that you added in the end of your line,delete it.
    – Charaf JRA
    Commented Aug 25, 2013 at 12:58
  • Not yet, this is the error " Undefined variable: one_page_ahkams in"
    – user1807367
    Commented Aug 25, 2013 at 13:00
  • $one_page_ahkams = array(); without []
    – Charaf JRA
    Commented Aug 25, 2013 at 13:02
-1

Just put that: 'ahkams' => array($one_page_ahkams), but check the content of $one_page_ahkams

1
  • this will send ahkams with the value $one_page_ahkams as string not as array ?Are you sure that's what you are looking for ?
    – Charaf JRA
    Commented Aug 25, 2013 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.