<?php
$username='miguelde_modulo4';
$password='modulo4';
$dbname='miguelde_modulo4';
$host='localhost';
echo'
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  <link  href="css/style.css" rel="stylesheet">
  <!-- Custom styles for this template -->
</head>

<h3>Site do Gabriel - Listagem de Leituras</h3>
<table border=2>
<tr>
<td>IdLeitura</td>
<td>Placa MAC</td>
<td>Nome da Placa MAC</td>
<td>Data</td>
<td>Hora</td>
<td>Valor</td>
</tr>

';

try {
 $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
 $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 $sql='SELECT leitura.idleitura,
 leitura.mac_idmac,
 mac.nome,
 leitura.dataleitura,
 leitura.horaleitura,
 leitura.valor
 from leitura,mac
 where leitura.mac_idmac=mac.idmac
 order by leitura.idleitura DESC

  ';
 $data = $conn->query($sql);
 foreach($data as $row) {
    echo'<td>'.($row[0]).'</td>';
    echo'<td>'.($row[1]).'</td>';
    echo'<td>'.($row[2]).'</td>';
    echo'<td>'.($row[3]).'</td>';
    echo'<td>'.($row[4]).'</td>';
    echo'<td>'.($row[5]).'</td><tr>';
  
 }echo'</table>';

} catch(PDOException $e) {
 echo 'ERROR: ' . $e->getMessage();
}
 ?>