我有PHP代码我们可以调用此代码BLOCKONE:
$maker = "SELECT vidMaker FROM videoinformation";
if ($result = mysqli_query($con, $maker)) {
while ($row = mysqli_fetch_row($result)) {
$values = explode(',',$row[0]);
foreach($values as $v)
if (!empty($v)) {
printf ("<img class=\"makerImg\" src=\"addVid/maker/%s.jpg\">", $v);
}
}
mysqli_free_result($result);
}
else{
echo"PM administrator with an error";
}
我有很多PHP代码:
<!DOCTYPE html>
<head>
</head>
<body>
<?php>
.
.
.
.
.
.
.
.
.
.
.
.
BLOCKONE
.
.
.
.
.
.
.
.
.
.
.
?>
</body>
</html>
问题是 BEFORE BLOCKONE所有mysqli查询都正常工作,我可以显示信息,图片等,但 AFTER BLOCKONE没有任何查询正在运行。
为什么我在这段代码中完全知道问题?因为如果删除它...完整的代码工作正常。而且我不太确定要解决它。
这是完整的代码:
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<?php include 'BSH.php' ?>
<link rel="stylesheet" type="text/css" href="CSS/ldvid.css">
<script type="text/javascript" src="java/FWDUVPlayer.js"></script>
<!-- Setup video player-->
<script type="text/javascript">
<?php include 'video/settings.php'; ?>
</script>
</head>
<body>
<?php include_once 'userPages/check_login_status.php';?>
<?php include_once 'incIndex/headerTop.php'; ?>
<?php include_once 'incIndex/footer.php'; ?>
<?php
// here we get the incomming video id (videoinfo.php?id=123)
$video_id = $_GET['id'];
// build a database query to select the videoInformation
// here we use WHERE to select the video_id we want
$query = 'SELECT newsvid.id, videoinformation.id, videomain.id, newsvid.vidTitle, newsvid.imgCover, videoinformation.vidLD, videoinformation.vidYear, videoinformation.vidCity, videoinformation.vidZanr, videoinformation.vidZanr2,videoinformation.vidZanr3,videoinformation.vidQuality, videoinformation.vidTranslated, videoinformation.vidMaker, videoinformation.vidRoles, videoinformation.vidTime, videoinformation.imgShot1, videoinformation.imgShot2, videoinformation.imgShot3, videomain.vidMUrl FROM newsvid, videomain, videoinformation WHERE newsvid.id = videoinformation.id AND newsvid.id = videomain.id AND newsvid.id = '. $video_id ;
// lets connect and do the query
include 'connect/con.php';
$result = mysqli_query($con, $query);
echo "<div class=\"ldCover\">";
while($row = mysqli_fetch_array($result)) {
echo "<div class=\"panel panel-default\"><div class=\"panel-heading\">";
echo "<div><strong><h3>" . $row['id']. " | " . $row['vidTitle'] . "</h3></strong></div>";
echo "</div><div class=\"panel-body\">";
echo "<div class=\"imgCover\"><img style=\"width:200; height:320px\" class=\"img-thumbnail\"src=\"upload/videoCover/" . $row['imgCover'] . "\"></div>";
echo "<div class=\"vidLD\">
<table>
<tr><td class=\"tdBR\"><strong> Years: </strong></td><td >" . $row['vidYear'] . "</td></tr>
<tr><td class=\"tdBR\"><strong> City: </strong></td><td >". $row['vidCity'] . "</td></tr>
<tr><td class=\"tdBR\"><strong> Zanr: </strong></td><td >". $row['vidZanr'] ." , ". $row['vidZanr2'] ." , ". $row['vidZanr3'] . "</td></tr>
<tr><td class=\"tdBR\"><strong> Quality: </strong></td><td >". $row['vidQuality'] . "</td></tr>
<tr><td class=\"tdBR\"><strong> Translated: </strong></td><td >". $row['vidTranslated'] . "</td></tr>
<tr><td class=\"tdBR\"><strong> Video time: </strong></td><td >". $row['vidTime'] . "</td></tr>
</table>" . $row['vidLD'] . "</div></div>";
echo "<div class=\"panel-body\" style=\"border-top: 1px solid; border-bottom: 1px solid; border-color:#ddd\"><div class=\"vidDesc\">
</div>";
echo "<div class=\"vidMR\">
<div><strong> Maker: </strong>" . $row['vidMaker'] . "</div><div>";
$maker = "SELECT vidMaker FROM videoinformation WHERE id=".$row['id'];
if ($result = mysqli_query($con, $maker)) {
while ($row = mysqli_fetch_row($result)) {
$values = explode(',',$row[0]);
foreach($values as $v)
if (!empty($v)) {
printf ("<img class=\"makerImg img-circle\" src=\"addVid/maker/%s.jpg\">", $v);
}
}
mysqli_free_result($result);
}
else{
echo"PM administrator with an error";
}
echo"</div><div><strong> Roles: </strong>". $row['vidRoles'] . "</div>
<div><table>";
$role = "SELECT vidRoles FROM videoinformation WHERE id=".$row['id'];
if ($result = mysqli_query($con, $role)) {
while ($row = mysqli_fetch_row($result)) {
$values = explode(',',$row[0]);
foreach($values as $v)
if (!empty($v)) {
printf ("<img class=\"roleImg img-circle\" src=\"addVid/roles/%s.jpg\">", $v);
}
}
mysqli_free_result($result);
}
else{
echo"PM administrator with an error";
}
echo "</table></div></div></div>";
echo"<div class=\"panel-body\"><div class=\"screenshots\">";
echo "<div class=\"imgShot1\"><img style=\"width:245px; height:140px\" class=\"img-thumbnail\" src=\"upload/" . $row['imgShot1'] . "\"></div>";
echo "<div class=\"imgShot2\"><img style=\"width:245px; height:140px\" class=\"img-thumbnail\" src=\"upload/" . $row['imgShot2'] . "\"></div>";
echo "<div class=\"imgShot3\"><img style=\"width:245px; height:140px\" class=\"img-thumbnail\" src=\"upload/" . $row['imgShot3'] . "\"></div>";
echo"</div>";
echo "</div><div class=\"panel-footer\">";
echo "<div class=\"vidMUrl\">
<div id=\"myDiv\"></div>
<ul id=\"playlists\" style=\"display:none;\">
<li data-source=\"playlist1\" data-playlist-name=\"MY HTML PLAYLIST\" data-thumbnail-path=\"content/thumbnails/large1.jpg\">
</li></ul>
<ul id=\"playlist1\" style=\"display:none;\">
<li data-thumb-source=\"content/thumbnails/small-fwd.jpg\" data-video-source=\"". $row['vidMUrl'] . "\" data-poster-source=\"upload/videoCover/" . $row['imgCover'] . "\" data-downloadable=\"yes\">
</li></ul>
</div>";
echo "</div></div></div>";
}
mysqli_close($con);
?>
</body>
</html>
答案 0 :(得分:1)
您假设获得多行,但您总是重写:
while ($row = mysqli_fetch_array($result)) {
在您的主循环中,您始终会重写$result
和$row
变量。
在while循环中,使用$result2
和$row2
。