我有一个页面运行在使用SQLite作为数据库的本地网络服务器上。作为其使用的本地语言,我不担心将所有结果加载得非常快而在一页上列出所有结果。我遇到了一个问题,尽管从SQLite3显示500个结果后,格式变了,开始将它们堆叠在一起。之前的一切都很好。其用php编写。信息是使用htmlspecialchars
输入到数据库中的,所以我不认为这是问题所在。构建循环中每条记录的代码是
$list = '';
while($row = $results->fetchArray()) {
$id = $row["id"];
$MovieTitle = $row["MovieTitle"];
$MovieYear = $row["MovieDate"];
$MovieRes = $row["MovieRes"];
$FileName = $row["FileName"];
$Summary = $row["Summary"];
$Genres = $row["Genres"];
$PictureLocation = $row["PictureLocation"];
$Rating = $row["Rating"];
$ReleaseDate = $row["ReleaseDate"];
$list .= '<div class="box">
<div class="movie">
<div class="movie-image"><span class="play"><a href="movielist.php?movie='.$FileName.'"><span class="name">'.$MovieTitle.'</span></span><img src="'.$ThumbnailPic.'" alt=""></a></div>
<div class="rating">
<p><a href="movie-info.php?movie='.$id.'">RATING: </a>'.$Rating.'</p>
<div class="stars">
<div class="'.$StarGraphic.'"></div>
</div>
<span class="comments"></span></div>
</div>';
}
我只是在html中将它们回显
<html>
<body>
<div id="main">
<br>
<?php echo $list; ?>
</div>
</body>
</html>
最佳答案
您的HTML错误,您没有正确关闭<div class="box">
和<span class="play">
标记。
正确的HTML是:
<div class="box">
<div class="movie">
<div class="movie-image">
<span class="play">
<a href="movielist.php?movie='.$FileName.'">
<span class="name">'.$MovieTitle.'</span>
<img src="'.$ThumbnailPic.'" alt="">
</a>
</span>
</div>
<div class="rating">
<p>
<a href="movie-info.php?movie='.$id.'">RATING: </a>'.$Rating.'
</p>
<div class="stars">
<div class="'.$StarGraphic.'"></div>
</div>
<span class="comments"></span>
</div>
</div>
</div>
麻生太郎,您可以在数据库记录中包含一些标签或引号。因此,您必须在输出http://php.net/manual/en/function.htmlspecialchars.php之前使用转义变量
像这样:
$list = '';
while($row = $results->fetchArray()) {
$id = htmlspecialchars($row["id"]);
$MovieTitle = htmlspecialchars($row["MovieTitle"]);
$MovieYear = htmlspecialchars($row["MovieDate"]);
$MovieRes = htmlspecialchars($row["MovieRes"]);
$FileName = htmlspecialchars($row["FileName"]);
$Summary = htmlspecialchars($row["Summary"]);
$Genres = htmlspecialchars($row["Genres"]);
$PictureLocation = htmlspecialchars($row["PictureLocation"]);
$Rating = htmlspecialchars($row["Rating"]);
$ReleaseDate = htmlspecialchars($row["ReleaseDate"]);
$list .= '<div class="box">
<div class="movie">
<div class="movie-image"><span class="play"><a href="movielist.php?movie='.$FileName.'"><span class="name">'.$MovieTitle.'</span></span><img src="'.$ThumbnailPic.'" alt=""></a></div>
<div class="rating">
<p><a href="movie-info.php?movie='.$id.'">RATING: </a>'.$Rating.'</p>
<div class="stars">
<div class="'.$StarGraphic.'"></div>
</div>
<span class="comments"></span></div>
</div>';
}