2016-03-18 47 views
-2

我是初学者,在PHP和HTML,所以我需要你的帮助。 我想显示数据从我的sql数据库创建使用phpmyadmin,到一个PHP页面。从sql数据库显示数据到apache2服务器中的html表格

我在网上搜索,发现类似的话题,但还是有问题

DB:WBAN ...

表名:杰克...

列显示:温度图,脉搏,运动...

这里是我的代码,一个空白页出现时,要求 “本地主机/ Jack.php”

<?php 

$conn=mysql_connect('localhost', 'root', 'MYPASSWORD'); 
mysql_select_db('wban'); 


    if(! $conn) { 
    die('Could not connect: ' . mysql_error()); 
     } 

$query = "SELECT * FROM Jack"; 
$result = mysql_query($query); 

?> 

<html> 
<head> <title> Jack Status </title> </head> 
<body> 

<table width="600" border="1" cellpadding="1" cellspacing="1"> 
<tr> <!-- header row --> 
<th>Data</th> 
<th>Latest Readings</th> 
<th>Average</th> 
<th>Standard Deviation</th> 
<th>Condition</th> 
</tr> 

<?php 

while($row = mysql_fetch_assoc($result)){ //Create a loop to loop through results 
    echo "<tr>" 
    echo "<td>.$row['Temprature'].</td>"  
    echo "<td>.$row['Pulse'].</td>" 
    echo "<td>.$row['Motion'].</td>" 
    echo "</tr>" 
    }//end while 
mysql_close(); //close out the database connection 
?> 
</table> 
</body> 
</html> 
+0

你的问题是假设你有一个工作的Web服务器。你可以让它显示简单的.html页面?它是否配置为处理PHP页面? –

+0

http://php.net/manual/en/function.error-reporting.php –

回答

2

确保关闭每个php语句的匹配引号,并在语句结尾处添加分号。

点运算并不在字符串中的工作文字,那么近两倍每次你需要应用运营商,像这次报价:

<?php 

while($row = mysql_fetch_assoc($result)){ //Create a loop to loop through results 
echo "<tr>"; 
echo "<td>".$row['Temprature']."</td>"; 
echo "<td>".$row['Pulse']."</td>"; 
echo "<td>".$row['Motion']."</td>"; 
echo "</tr>"; 
}//end while 
mysql_close(); //close out the database connection 
?> 
+2

*“试试这个”*不会“解释”为什么他们的代码失败。 –

+0

@Fred我刚刚编辑了包含解释的答案。 – Indrajit

+0

谢谢。但是,您忽略了关于缺少的结束分号的部分。 ;-)这将抛出解析错误。编辑:你补充说,很好;-)现在“这是一个答案。 *干杯* –

相关问题