Screening Json of the mass, decommissioning of the higher value, followed by the



  • Good day. Help me figure it out if it's not hard. There's a json mass.

    [  
       {  
          "text":"text",
          "text":"text",
          ...
          "last_episode_time":"2015-11-22 12:00:00"
       },
       {  
          "text":"text",
          "text":"text",
          ...
          "last_episode_time":"2015-11-22 13:00:00"
       },
       {  
          "text":"text",
          "text":"text",
          ...
          "last_episode_time":"2015-11-20 14:00:00"
       }
    ]
    

    I'll get his trail.

    <?php
    $url = file_get_contents("http://site.ru/api/test.json");
    $content = json_decode($url, true);
    ?>
    

    Field values need to be compared last_episode_timeand raise more. 2015-11-22 13:00:00

    Next, it's meaning to be written in bud.

    <?php
    $servername = "localhost";
    $username = "test";
    $password = "test";
    $dbname = "test";
    $id = "770";
    $date = "2015-11-22 13:00:00";
    

    $conn = mysqli_connect($servername, $username, $password, $dbname);

    if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
    }
    $sql = "UPDATE dle_post SET date='$date' WHERE id=$id";

    if (mysqli_query($conn, $sql)) {
    echo "good";
    } else {
    echo "bad: " . mysqli_error($conn);
    }
    mysqli_close($conn);
    ?>

    And about the bud footage, if you can check that every time you don't rewrite the OBD.

    Thank you.



  • Hello! If it's a record check, it's like,

    $sql = "UPDATE dle_post SET date='$date' WHERE id=$id AND date!='$date'";
    

    If the pre-record check is:

    $url = file_get_contents("http://site.ru/api/test.json");
    $cache = '';
    if (file_exists("test.json")) {
        $cache = file_get_contents("test.json");
    }
    if ($cache != $url) {
        file_put_contents("test.json", $url);
        //а здесь Ваш код, который обновляет данные в таблице.
    }
    

    The option is to get a date every time from clashing it with the same macar. It'll save memory, but it'll take time.

    And about the first question I've seen second...

    $dates = [];
    foreach ($content as $row) {
       $dates[] = $row->last_episode_time; //собираем даты в массив
    }
    rsort($dates); //сортируем в обратном порядке, большая-первая
    $date = array_shift($dates); //вуаля
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2