Check for changes in an html table

Asked

Viewed 85 times

0

Good evening. I have a table that I pick up via Curl. It updates every 30 seconds, and displays in an html. This table has the status of a character in a game (live or dead).

I wanted to know how to generate an Alert of each row of the table that was modified (went from live to dead, 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 shows me a table. 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 ALIVE. I’m lost in that part.

  • Post your code and what problem you’re having, that members of the community will help you and answer your problem more easily and quickly,

  • https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-n%C3%83o-fazer-perguntas/5484#5484

  • Sorry, I was on my cell phone last night. Code posted!

1 answer

1


My guess is you’ll have to read the chart into some variable. You do a foreach for each line, and you keep the name and state in a global variable, when you re-compare and update to that variable.

by variable I mean some array name(key) and value (monster state)

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>
    <table id="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>
  • There would be some example of how to do this: It may be an answered question, link, anything. Thank you!

  • 1

    I added an example.. now what you have to think about is that you need the first time you enter the page you have q popular the array, eg in documentready.. and from then on this code is worth to you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.