1

this is my contoller

$pid = json_decode(file_get_contents('php://input'), true);
            foreach ($pid as $key => $value) {
                foreach ($value as $keys => $values) {
                    $c_res = $this->Model_master->get_sup($values);
                    echo json_encode($c_res, 200);
                } 
             } 

this is my model

                $q = $this->db->select('contact_number')->from('shopxie_people')
                                ->where("p_id = ".$value)
                                ->get();
                return $q->result_array();

this shows me result in html form but when i change it to json it gives me

SYntax error

also in postman content-type is showing as text/html;

why does it happen even after encoding in json in my code?

7
  • What do you mean by "change it to json"? Can you share the exact error message? Commented Jul 17, 2018 at 6:50
  • what is 200 in json_encode($c_res, 200) just remove it Commented Jul 17, 2018 at 6:50
  • @pradeep still it gives the same error Commented Jul 17, 2018 at 6:51
  • keep it out of foreach loop Commented Jul 17, 2018 at 6:52
  • @NicoHaase i am using postman so i get option of changing my output to html, json, xml, text, auto Commented Jul 17, 2018 at 6:52

1 Answer 1

3

Hope this will help you :

Do something like this in your controller :

foreach ($pid as $key => $value) 
{
   foreach ($value as $keys => $values) 
   {
      $c_res[] = $this->Model_master->get_sup($values);  
   }
}
echo json_encode($c_res);
exit;
Sign up to request clarification or add additional context in comments.

1 Comment

pleasure is mine, happy coding

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.