试图从php/mysql获取信息的HTML页面
这个相当简单的问题令我烦恼。我有一个用CSS设计的html页面。我有一个简单的php页面,返回mysql站点的最新记录。我需要在“leftContent”div的html页面中显示此信息 正在使用的“latest.php”页面是:试图从php/mysql获取信息的HTML页面,php,html,mysql,Php,Html,Mysql,这个相当简单的问题令我烦恼。我有一个用CSS设计的html页面。我有一个简单的php页面,返回mysql站点的最新记录。我需要在“leftContent”div的html页面中显示此信息 正在使用的“latest.php”页面是: <?php /* Return the latest date and record for the left pane. */ include 'ESP8266_dbLogin.php'; $result = mysqli_query($link, "S
<?php
/*
Return the latest date and record for the left pane.
*/
include 'ESP8266_dbLogin.php';
$result = mysqli_query($link, "SELECT * FROM `thLog` ORDER BY logID DESC LIMIT 1") or die ("Connection error");
while($row = mysqli_fetch_array($result)) {
echo "Date: " . $row['logDate'] . "<br>";
echo "lightVal: " . $row['lightVal'];
}
mysqli_close($link);
?>
“index.html”代码如下所示,php变量的目标DIV为contentLeft:
<!DOCTYPE html>
<!-- Basic Layout -->
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Sparks - Monitor</title>
<link rel="stylesheet" type="text/css" href="css/default.css">
<link href='//fonts.googleapis.com/css?family=Baloo' rel='stylesheet'>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript" src="data24.js" ></script>
</head>
<body>
<div id="wrapper">
<div id="main">
<div id="banner">
<div id="bannerLeft">
<img class="bannerImg" alt="ESP8266 Logo" src="images\imgESP8266.png">
</div>
<div id="bannerRight">
<img class="bannerImg" alt="Settings Icon" src="images\imgGear.png">
</div>
<div id="bannerMain">
<h1>SPARKS Energy Monitor - Home</h1>
</div>
</div>
<div class="content" id="contentLeft">
<h2>Current Usage:</h2>
<p> The current lightVal and date should be here<p>
</div>
<div class="content" id="contentRight">
Generating chart, please wait...
</div>
</div>
</div>
</body>
<html>
火花监测器
火花能量监测器-家用
当前使用情况:
当前lightVal和日期应在此处
正在生成图表,请稍候。。。
如果您能以最有效的方式将php变量(lightVal)放入html页面,我们将不胜感激。我知道,愚蠢的问题 1)将您的index.html
重命名为index.php
2) 用PHP代码替换目标
div
:
<div class="content" id="contentLeft">
<h2>Current Usage:</h2>
<?php
/*
Return the latest date and record for the left pane.
*/
include 'ESP8266_dbLogin.php';
$result = mysqli_query($link, "SELECT * FROM `thLog` ORDER BY logID DESC LIMIT 1") or die ("Connection error");
while($row = mysqli_fetch_array($result)) {
?>
<p class="dateClass"><?=$row['logDate']?></p>
<p class="lightValClass"><?=$row['lightVal']?></p>
<?
}
mysqli_close($link);
?>
</div>
当前使用情况:
这应该足够了,只需从浏览器中调用index.php。实际上,最好的选择是开始使用Twig进行模板制作。或者,如果您想推出自己的模板系统:。这很有效。如何使用单独的default.css文件格式化它?谢谢