Hello! It is necessary to implement the json array output using php, its visual appearance is as follows:

{"akk": [["1", "Dmitry", "Novickov"], ["2", "Evgenuy", "Novickov"]]}

You need to output just such a JSON array .. Please help implement this.

you should not change the wording of the question, but create a new one. This question has almost nothing to do with the one that was originally.

Елена Левина2021-02-23 00:00:09

In general, you just need to figure out how the json_encode php function converts arrays to json. To get a js array, the original array must be indexed, if the original was associative, you get a js object.

Елена Левина2021-02-23 00:00:09
  • Answer # 1

    To begin with, you should have shown how you choose from the database, otherwise now we can only guess.

    It's actually relatively simple.

    $ data= array (); //write to this array what we select from the base
    $ ta= mysql_query ("select * from table"); //make a request to the database
    while ($ row= mysql_fetch_assoc ($ ta)) {//fetch each row of the result
                                          //as an associative array
        $ data []= $ row; //add a string from the selection as a new element of the resulting array
    echo json_encode ($ data); //and send it as json
  • Answer # 2

    In the visual editor mysql , there is a Export function with a choice of format. You can export both the entire database and a separate table.

    Outputs in the format:

    [{"USER": "634155305", "ID_GREP": "109927", ...}, {..}]

    It will be enough to replace the regular brackets in any text editor or preg_replace in your hands.