您好我写下了以下PHP脚本,以HTML表格的形式显示在sqlite数据库中编写的数据。当我打开页面时,我只看到标题控制面板。我已将其保存为我的服务器根目录下的index.php。
<html>
<head>
<title>Switch and Status Report</title>
</head>
<body>
<h1>Control Panel</h1>
<table border="1" style="width:100%">
<?php
$dbhandle = sqlite_open('db/pj.db', 0666, $error);
if (!$dbhandle) die ($error);
$query = "SELECT * FROM state";
$result = sqlite_query($dbhandle, $query);
if (!$result) die("Cannot execute query.");
$array = sqlite_fetch_all($result, SQLITE_NUM);
echo($array);
for ($x = 0; $x <= 6; $x++) {
$curarr = $array[$x];
$curpin = $curarr[0];
$curname = $curarr[1];
$curstate = $curarr[2];
$curdep = $curarr[3];
$textst = "";
$linkst = "";
$textdep = "";
$linkdep = "";
if($curstate==(0)){
$textst = "Turn On";
$linkst = "statechange.php";
}
elseif($curstate==(1)){
$textst = "Turn Off";
$linkst = "statechange.php";
}
if($curdep==(0)){
$textst = "Make Motion Dependent";
$linkst = "motionchange.php";
}
elseif($curstate==(1)){
$textst = "Make Motion Independent";
$linkst = "statechange.php";
}
echo("<tr>");
echo("<td>$curpin</td>");
echo("<td>$curname</td>");
echo("<td><a href='$linkst'>$textst</a></td>");
echo("<td><a href='$linkdep'>$textdep</a></td>");
echo("</tr>");
sqlite_close($dbhandle);
}
?>
</table>
</body>
</html>
请排查并帮助我。提前谢谢。
答案 0 :(得分:1)
$ curarr部分缺少你。在上面的第18行,看到你已经省略了$符号。它产生了一个错误。
<html>
<head>
<title>Switch and Status Report</title>
</head>
<body>
<h1>Control Panel</h1>
<table border="1" style="width:100%">
<?php
$dbhandle = sqlite_open('db/pj.db', 0666, $error);
if (!$dbhandle) die ($error);
$query = "SELECT * FROM state";
$result = sqlite_query($dbhandle, $query);
if (!$result) die("Cannot execute query.");
$array = sqlite_fetch_all($result, SQLITE_NUM);
echo($array);
for ($x = 0; $x <= 6; $x++) {
$curarr = $array[$x];
$curpin = $curarr[0];
$curname = $curarr[1];
$curstate = $curarr[2];
$curdep = $curarr[3];
$textst = "";
$linkst = "";
$textdep = "";
$linkdep = "";
if($curstate==(0)){
$textst = "Turn On";
$linkst = "statechange.php";
}
elseif($curstate==(1)){
$textst = "Turn Off";
$linkst = "statechange.php";
}
if($curdep==(0)){
$textst = "Make Motion Dependent";
$linkst = "motionchange.php";
}
elseif($curstate==(1)){
$textst = "Make Motion Independent";
$linkst = "statechange.php";
}
echo("<tr>");
echo("<td>$curpin</td>");
echo("<td>$curname</td>");
echo("<td><a href='$linkst'>$textst</a></td>");
echo("<td><a href='$linkdep'>$textdep</a></td>");
echo("</tr>");
sqlite_close($dbhandle);
}
?>
</table>
</body>