如何修复此代码我不知道问题来自哪里?
$results = $mysqli->prepare("SELECT id, title, tags,thumb,views,duration,date,owner FROM `videos` ORDER BY id DESC LIMIT $position, $items_per_group");
$results->execute(); //Execute prepared Query
$results->bind_result($id_r, $title_r, $tags_r,$thumb_r,$views_r,$duration_r,$date_r,$owner_r); //bind variables to prepared statement
while($results->fetch()){ //fetch values
$resultsa = $mysqli->prepare("SELECT id,user FROM `users` where `owner`='$owner_r'");
$resultsa->execute(); //Execute prepared Query
$resultsa->bind_result($f,$user_getbyid); //bind variables to prepared statement
$resultsa->fetch();
?>
<a href="video/<?php echo $id_r; ?>">
<div class="video">
<div class="img"><img src="<?php echo $thumb_r; ?>"/></div>
<div class="title"><h2><?php echo htmlspecialchars_decode($title_r); ?></h2></div>
<div class="pub_by"><span id="pub_by_user">Published by : <a href="user/"><?php echo $user_getbyid; ?></a></span><span id="pub_time"><?php echo htmlspecialchars_decode($date_r); ?></span></div>
<div class="time"><?php echo $duration_r; ?></div>
<div class="info">
<ul>
<li><?php echo $views_r; ?></li>
<li>148</li>
<li>45</li>
</ul>
</div>
</div>
</a>
<?php
}
$mysqli->close();
}
?>
请修复此代码并解释为什么它不能像那样
答案 0 :(得分:1)
有两个可能出现问题的地方 - 如果不知道行号,则无法说出哪一行。
您对$mysqli->prepare
的一次调用失败,这表明您生成的SQL不正确。
示例的第一行中有两个未定义的变量(根据至少发布的代码段),这将导致查询不正确。