2

I'm outputting my DB result like this:

foreach($result as $row) {
    echo json_encode($row);
}

This outputs the following:

{"nummer":"600","name":"Location Name 600"}{"nummer":"698","name":"Location Name 698"}{"nummer":"1110","name":"Location Name 1110"}

Is this the right way? Do I have to seperate the result rows from each other?

Edit: If I get a callback id from jquery, what way would I format this into jsonp? To be more specific, I'd like to put an value containing the total amount of results, and then all results found, in jsonp (jquery sends me the id for a callback, which I'll have to put into the output).

2
  • This isnt valid JSON - you can check here and what is $result ? Commented May 4, 2012 at 8:15
  • It's the result array from a database query (2D Array, first array is numeric, second array is associative) Commented May 4, 2012 at 8:18

1 Answer 1

3

simply...

echo json_encode($result);
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, that was easy. Thanks alot!

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.