E
E
Egor Kornyshov2015-09-01 18:16:22
MySQL
Egor Kornyshov, 2015-09-01 18:16:22

How to output data from json sorting output by only one field?

So, there is a json file, something like this:

{
    "games": [
        {
            "name": "FlatOut 2",
            "image": "http:\/\/www.game-ost.ru\/static\/covers_soundtracks\/1\/1\/11195_599433.jpg",
            "game_key": "DNVI5-74JHP-OLOQ2",
            "start": 1441052980,
            "winner": "https:\/\/vk.com\/id164746581"
        },
        {
            "name": "Anachronox",
            "image": "http:\/\/www.abcgames.sk\/udaje\/cd_obaly\/2\/230_f1.jpg",
            "game_key": "GPXFT-J9GJ4-PF58L",
            "start": 1441114401
        },
        {
            "name": "Daikatana",
            "image": "http:\/\/files.khinsider.com\/vgwallpaper\/1280x1024\/685-daikatana-005-wywlf.jpg",
            "game_key": "GPXFT-J9GJ4-PF58L"
        }
    ]
}

I need to display only the data that contains the winner string.
Essence - there is a competition for the selection of the key to the game. The game is selected first in the json file list. If the key is matched, the winner string is assigned to the array, and the next string is selected, where there is no winner string. The tuba is written with the line start and the contest is started in a new way.
I want to make a file that will output "winning history". That is, it will indicate which games were played, when, what was the key and who won.
I didn't write the system. In programming, I do not understand even the lines.
Can you help with writing a handler?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2019-03-20
@MikMik

https://dev.mysql.com/doc/refman/5.7/en/view-restr...

Before MySQL 5.7.7, subqueries cannot be used in the FROM clause of a view.

R
retvizan, 2019-03-20
@retvizan

because views cannot have a subquery in the FROM part of the
emnip, in recent versions there is no such restriction

V
vista1x, 2015-09-01
@RJStrannik

$json = '{
  "games": [
    {
      "name": "FlatOut 2",
      "image": "http:\/\/www.game-ost.ru\/static\/covers_soundtracks\/1\/1\/11195_599433.jpg",
      "game_key": "DNVI5-74JHP-OLOQ2",
      "start": 1441052980,
      "winner": "https:\/\/vk.com\/id164746581"
    },
    {
      "name": "Anachronox",
      "image": "http:\/\/www.abcgames.sk\/udaje\/cd_obaly\/2\/230_f1.jpg",
      "game_key": "GPXFT-J9GJ4-PF58L",
      "start": 1441114401
    },
    {
      "name": "Daikatana",
      "image": "http:\/\/files.khinsider.com\/vgwallpaper\/1280x1024\/685-daikatana-005-wywlf.jpg",
      "game_key": "GPXFT-J9GJ4-PF58L"
    }
  ]
}';


  $data = json_decode($json, true);

  foreach ($data['games'] as $game)
  {
    if (isset($game['winner']))
    {
      //выводим
      print $game['name'] . "<br>";
    }
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question