Firts私はPHPを使用してMySQLデータベースから値を取り出しました。これは私のPHPコードです:phpからhtmlへのパス値
<?php
$dsn = 'mysql:host=localhost;dbname=iot';
$username = 'root';
$password = '';
$dbh = new PDO($dsn, $username, $password);
//build the query
$query="SELECT temperaturevalue, humidityvalue FROM sensors";
//execute the query
$data = $dbh->query($query);
//convert result resource to array
$result = $data->fetchAll(PDO::FETCH_ASSOC);
//view the entire array (for testing)
//print_r($result);
//display array elements
foreach($result as $output) {
echo "temperature Value";
echo $output['temperaturevalue'];
echo "<br/>";
echo "<br/>";
echo "humidity ";
echo $output['humidityvalue'] ;
}
?>
ここでは、この値をHTMLページに表示します。この私のhtmlコード:
<!DOCTYPE html>
<html>
<head>
<title>Smart house</title>
<meta http-equiv="refresh" content="30">
<meta charset="UTF-8">
<style>
h1 {color:orange;
font-style: italic;
font-size:300%}
img {
width:100%;
}
</style>
</head>
<body>
<h1><strong>Connect and control</strong></h2>
<P style="text-align:center;"><img src="myhouse.png" alt="smart house" style="width:50px;height:40px;"></p>
<br>
</body>
</html>
私はexempleのための私のhtmlページ上で表示するために何を追加する必要があります:これは非常に簡単です
Temperature value : 25.56
Humidity value : 300
Htmlファイルは静的です。つまり、動的データを渡すことはできません。 PHPのページ自体にhtmlを印刷してください。 – NoImaginationGuy