Código Fonte:



<html>
<head>
<title>PHP - MySQL</title>
</head>
<body>
<h1>Exercício: Organizar os dados numa tabela em PHP</h1>
<?php

include '/home/rml/acessoMysql/mysql_connect.php';



if (!
mysqli_select_db$conn,"smpw")) {
    die(
"Falhou o acesso à base de dados. Erro: " mysqli_error($conn));
}


$sql "SELECT * FROM lixo";

$result mysqli_query($conn$sql);


echo 
"<table width=\"240\" border=\"1\">

  <caption align=\"top\">
    <h3>Dados dos Sensores</h3>
  </caption>

  <tr>
    <th scope=\"col\">Dados</th>
    <th scope=\"col\">Valor</th>
    <th scope=\"col\">Sensor</th>
  </tr>"
;

$result mysqli_query($conn$sql);
while(
$row mysqli_fetch_array($result))

  {

  echo 
"<tr>";

  echo 
"<td>" $row['dados'] . "</td>";

  echo 
"<td>" $row['valor'] . "</td>";
  
  echo 
"<td>" $row['sensor'] . "</td>";


  echo 
"</tr>";

  }

echo 
"</table>";



mysqli_free_result($conn); //libertar os resultados da memória




mysqli_close($conn);

?> 
</body>
</html>