Check changes in a table html

0

Good evening. I have a table that I get via cURL. It refreshes every 30 seconds, and displays in an html. This table has the status of a character in a game (dead or alive).

I wanted to know how to generate an alert for each row of the table that was changed (moved from dead to alive, and vice versa).

cURL:

<?

$ch = curl_init("http://l2metal.com/?page=boss");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($ch);

preg_match('#<table[^>]*>(.+?)</table>#is', $page, $matches);
foreach ($matches as &$match) {
    $match = $match;
}
echo '<table>';
    echo $matches[1];
echo '</table>';

?>

JQuery:

$.get('http://meusite.com.br/boss.php', function(data){
  $("#boss").html(data);
})

This displays a table for me. So far it's OK, but I wanted a light of what I can do to display an alert when some monster changes from DEAD to LIVE. I'm lost in that part.

    
asked by anonymous 06.11.2017 / 03:20

1 answer

1

My opinion is that you will have to read the table into some variable. You make a foreach for each line, and you save the name and state in a global variable, when you compare them again and you update to that variable.

By variable I say some array of name (key) and value (state of the monster)

ex:

<html>

  <head>
    <script data-require="[email protected]" data-semver="3.1.1" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script></head><body><tableid="test">
      <tbody>
        <tr>
          <td>
          Jose
        </td>
          <td>
          Vivo
        </td>
          <td></td>
        </tr>
        <tr>
          <td>
          Andre
        </td>
          <td>
          Morto
        </td>
          <td></td>
        </tr>
        <tr>
          <td>
          Jose
        </td>
          <td>
          Vivo
        </td>
          <td></td>
        </tr>
        <tr>
          <td>
          Jose
        </td>
          <td>
          Vivo
        </td>
          <td></td>
        </tr>
      </tbody>
    </table>
    <script>

      var array ={"Jose":"Vivo", "Andre":"Vivo"};

       $("#test tr").each(function(index){
debugger;
         var key = $.trim($(this).find("td:first-child").text());
         var value = $.trim($(this).find("td:nth-child(2)").text());

         array[key] != value ? alert(key + " - ..") : "";
         array[key] = value;
                 });


</script>
  </body>

</html>
    
06.11.2017 / 11:59