0

i have this array,

$sql = "SELECT s.sitter_id,s.sitter_id,s.name as sitter_name,s.mobile_no FROM `maggie_trusted_circle` t INNER JOIN maggie_sitters s ON t.sitter_id = s.sitter_id Where t.mom_id =". $params['mom_id'];
        $trusted_circle = $this->db->executeQuery($sql);

and i am using this to acess more data via

for($i=0; $i<sizeof($trusted_circle); $i++)
        {

              $mutual_friend = $trusted_circle[$i]['sitter_id'];
              $mutual_friend_name = $trusted_circle[$i]['sitter_name'];
              $sql = "SELECT s.sitter_id,s.name as sitter_name,s.mobile_no FROM `maggie_trusted_circle` t INNER JOIN maggie_sitters s ON t.sitter_id = s.sitter_id Where t.mom_id =". $mutual_friend;
              $extended_trusted_circle[$i] = $this->db->executeQuery($sql);
              $extended_trusted_circle[$i]['mutual_friend_id']= $mutual_friend;
              $extended_trusted_circle[$i]['mutual_friend_name']= $mutual_friend_name;


        }

and encoding the response

 return json_encode(array('flag'=>1, 'message'=>'Success' ,'extended_trusted_circle'=>$extended_trusted_circle);

everything works fine, except the index numbers are also printed in the JSON Response

enter image description here

what could be the reason for this? i believe normally the index numbers are not printed along, am i missing something?

2
  • json_encode translates php arrays (that are indexed by integers) to hashes, and it used the indexes (converted to strings) as keys Commented Jan 20, 2016 at 12:23
  • BTW if you would show us the json output you want to achieve we might easier help you Commented Jan 20, 2016 at 12:24

2 Answers 2

1

The reason you see those 0-s is that:

$extended_trusted_circle[$i] = $this->db->executeQuery($sql);

return an array like:

array(0 => array('sitter_id'=>44,...))

0 is the row number, but it always returns only 1 row

Sign up to request clarification or add additional context in comments.

Comments

0

Try to die(); after json_encode

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.