php - How to create Nested Array inside Array with View_ID as common variable -


i want view_id common both objects.i try it. not proper response.there way combine both of them single array

how want it:

{ "success":true, "total":2,  "view_id":"v1", "config":[           {           "id":"1",           "button_id":"acc123_b1"           },           {           "id":"2",           "button_id":"acc123_b2"           }         ] } 

here php code:

  <?php include_once 'dbconfig.php'; if($_server['request_method'] == 'post') { // variables input data $mac_qr_code = $_post['mac_qr_code']; // variables input data  $resultarr = array(); $sql = "select * config mac_qr_code='".$mac_qr_code."'"; $result = $conn->query($sql);  if ($result->num_rows > 0) {     $resultarr = array('success' => true, 'total' => $result->num_rows);     while($row = $result->fetch_assoc()) {          $resultarr['config'][$row['id']] = array('id' => $row['id'], 'view_id' => $row['view_id'], 'button_id' => $row['button_id']);      }     $resultarr['config'] = array_values($resultarr['config']); } else {     $resultarr = array('success' => false, 'total' => 0);     echo "question 0 results"; } echo json_encode($resultarr);   }  ?> 

how showing

   {"success":true,"total":2,"config":[{"id":"1","view_id":"v1","button_id":"acc123_b1"},{"id":"2","view_id":"v1","button_id":"acc123_b2"}]} 

try this

$resultarr['view_id'] = $row['view_id']; $resultarr['config'][] = array('id' => $row['id'], 'button_id' => $row['button_id']); 

instead of this

$resultarr['config'][$row['id']] = array('id' => $row['id'], 'view_id' => $row['view_id'], 'button_id' => $row['button_id']); 

and remove this

$resultarr['config'] = array_values($resultarr['config']); 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -