[英]Display results according to a variable
I am trying to display a table according to a variable but I am getting errors on the view. 我试图根据变量显示一个表,但我在视图上出错。
Here is the database function that gets the results, I'm passing in the value $series
. 这是获取结果的数据库函数,我传入值
$series
。
function getReviews($series) {
global $db;
$query = 'SELECT review FROM reviews
where series = :series';
$statement = $db->prepare($query);
$statement->bindValue(':series', $series);
$statement->execute();
$reviews = $statement->fetchAll();
$statement->closeCursor();
return $reviews;
}
And here is the view 这是观点
<div id="reviews" class="tab-pane fade">
<h3>Reviews</h3>
<table>
<thead>
<tr>
<th>Review</th>
</tr>
</thead>
<tbody>
<?php foreach ($reviews as $review) : ?>
<tr>
<td><?php echo $reviews['review']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
I am getting some sort of result as there are 3 reviews under $series = 1
, but they aren't displaying 我得到了某种结果,因为在
$series = 1
下有3条评论,但它们没有显示
Notice: Undefined index: review in C:\\xampp\\htdocs\\WEBCA5LP\\view\\main.php on line 52
注意:未定义的索引:在第52行的C:\\ xampp \\ htdocs \\ WEBCA5LP \\ view \\ main.php中查看
Notice: Undefined index: review in C:\\xampp\\htdocs\\WEBCA5LP\\view\\main.php on line 52
注意:未定义的索引:在第52行的C:\\ xampp \\ htdocs \\ WEBCA5LP \\ view \\ main.php中查看
Notice: Undefined index: review in C:\\xampp\\htdocs\\WEBCA5LP\\view\\main.php on line 52
注意:未定义的索引:在第52行的C:\\ xampp \\ htdocs \\ WEBCA5LP \\ view \\ main.php中查看
You are echoing the wrong thing - $review not $reviews 你正在回应错误的事情 - $ review not not review
<?php foreach ($reviews as $review) : ?>
<tr>
<td><?php echo $review['review']; ?></td>
</tr>
<?php endforeach; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.