0

I Convert PHP Array To JSON Success But My target not full fill.

My out put is:

{"id":"145","logid":"","name":"asasa"}{"id":"144","logid":"","name":"qwsqwswq"}{"id":"145","logid":"","name":"asasa"}{"id":"144","logid":"","name":"qwsqwswq"}

My Requirement :

[{"id":"145","logid":"","name":"asasa"}{"id":"144","logid":"","name":"qwsqwswq"}{"id":"145","logid":"","name":"asasa"}{"id":"144","logid":"","name":"qwsqwswq"}]

Here my code:-

if ($AdminRecord) {

                    foreach($AdminRecord->result() as $results)
                    {
                      echo json_encode($results);
                    }
                }

1 Answer 1

4

You are outputting every row, instead try this:

$resultSet = Array();
if($AdminRecord){
    foreach($AdminRecord->result() as $result) {
       $resultSet[] = $result;
    }
}
echo json_encode($resultSet);
Sign up to request clarification or add additional context in comments.

3 Comments

That's Great R Singh, धन्यवाद
@AnshuPratapYadav , please change this to Accepted answer if it solved your query.
It's Working well Thanks R Singh.@

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.