2

I want use zachhunters json to html tabel script with my postressql db so i need a specific JSON string format but i dont know how to build it ... (i am new in json)

Link to the Script

I get my data using

$result = pg_fetch_array($rs, NULL, PGSQL_ASSOC);

When i use json_encode($result) i get this:

{"id":"2","surname":"Max","name":"Muster"} etc.

For the Script i need somthing like:

{ "d": "[{\"id\":1,\"Username\":\"Sam Smith\"},{\"id\":2,\"UserName\":\"Fred Frankly\"}]" }

How can i handle this?

1
  • I highly doubt that you need JSON containing a JSON string. You probably need JSON containing an array containing your row objects. Commented Nov 13, 2012 at 7:52

1 Answer 1

2

In each loop where you fetch an element from your database store the $result in an array $rows.

After the loop simply use json_encode(array('d' => $rows)) to create JSON containing all your data.

0

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.