javascript – Show JSON in table with js from php

I want to show the data I receive from a query made in a php file, in an html with a table, sounds simple, but I need to group by 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, let's say.
What I want to do is to group the orders (id_order) in a table according to the different states they passed (id_order_state).
so that I have a table of this style:

INITIAL STATUS | FINAL STATUS | NUMBER OF ORDERS (sum of order_id)

I share the code:

    connect_errno) {
    $ arrayData = array ("error" => "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 this could 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 ('Content-Type: application / json; charset = utf8');
echo $ json;
?>

I have the data inside the json, but I would like to know how to paint them in a table, making the grouping that I comment.

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

If you could explain to me a little how it goes sigma I have managed to make some graph but not passing data.

Regards and thanks for your attention.