javascript – Display JSON in an array with php js

I want to show the data I get from a query made in a php file, in a html with a table, it sounds simple, but I have to group one of the fields that I have in the json.

The serious thing, I have this json:

[{
id_order_history: "1",
id_employee: "0",
source_id: "1",
id_order_state: "1",
date_add: "2013-02-27 16:24:30"
}
{
id_order_history: "2",
id_employee: "0",
source_id: "2",
id_order_state: "3",
date_add: "2013-04-08 12:47:34"
}
...

Which is infinite, say.
What I want to do is group the commands (id_order) in a table according to the different states they have passed (id_order_state).
so that I have a table of this style:

INITIAL STATUS | FINAL STATUS | NUMBER OF ORDERS

I share the code:

    connect_errno) {
$ arrResponse = array ("error" => "The connection failed:". $ mysql-> connect_error);
} else {
$ mysqli-> set_charset ("utf8");
$ query = "SELECT * FROM ps_order_history limit 100";
if ($ result = $ mysql-> query ($ query)) {
// I think that might be too much for me.
$ arayData = array ();
while ($ row = $ result-> fetch_assoc ()) {
$ arrayData[]= $ row;
}
$ result-> free ();
} else {
$ arrayData = array ("error" => "Error");
}
$ mysql-> close ();
}
$ json = json_encode ($ arrayData);
header (& # 39; Content-Type: application / json; charset = utf8 & # 39;);
echo $ json;
?>

I have the data inside the JSON, but I would like to know how to paint them in a table, by doing the grouping I'm commenting on.

I hope you have explained me well and that you can help me. After organizing this json, I want to make a graph with SigmaJS.

If you could explain a little bit about how sigma is going, I managed to make a graph but not to transmit data.

Greetings and thank you for your attention.