<?php

include "conexao.php";

if (mysql_errno($conexao) > 0) {
  echo "Erro";
}

$string_sql = "SELECT * FROM esp32.sensor";

#echo $string_sql;
$dados = mysql_query($string_sql,$conexao) or die(mysql_error());
// transforma os dados em um array
$linha = mysql_fetch_assoc($dados);
// calcula quantos dados retornaram
$total = mysql_num_rows($dados);

?>
<html>
<head>
  <title>Animais</title>
</head>
<body>
  <table border="1">
    <tr align="center">
      <td>Identificador</td><td>Animal</td>
    </tr>
    <?php
    if($total > 0) {
      do {
        ?>
        <td align="right">&nbsp<?=$linha['id']?>&nbsp</td><td align="right">&nbsp<?=$linha['nome']?>&nbsp</td>
      </tr>
      <?php
    } while($linha = mysqli_fetch_assoc($dados));
  }
  ?>
</table>
</body>
</html>
<?php
// tira o resultado da busca da memória
mysql_free_result($dados);
?>
