二维数组 PHP PDO
有人可以帮忙吗?
我从 cms_page_part 表中提取下面的结果。我知道事实上应该有两行。一个“name”等于“body”,另一个存在的是“testionial”,但是我下面的查询只打印第一个。是因为我获取结果不正确吗?
<div class="feature-text">
<?php
$qpp = mysql_query("SELECT * FROM cms_page_part WHERE page_id=$id");
$rpp = $qpp->fetch(PDO::FETCH_BOTH);
foreach ($rpp as $row) {
?>
<div id="col1">
<p><?php echo $row['name']=='body' ? $row['content_html'] : NULL; ?></p>
</div>
<div id="col2">
<p class="testimonial"><?php echo $row['name']=='sidebar' ? $row['content_html'] : NULL; ?></p>
</div>
<?php
}
?>
</div>
Could anyone help with this please?
I am pulling the results in below from the cms_page_part table. I know for a fact there should be two rows. One where "name" is equal to "body" and the other that exists is "testionial" however my query below only prints the first one. Is it because im fetching the results incorrectly?
<div class="feature-text">
<?php
$qpp = mysql_query("SELECT * FROM cms_page_part WHERE page_id=$id");
$rpp = $qpp->fetch(PDO::FETCH_BOTH);
foreach ($rpp as $row) {
?>
<div id="col1">
<p><?php echo $row['name']=='body' ? $row['content_html'] : NULL; ?></p>
</div>
<div id="col2">
<p class="testimonial"><?php echo $row['name']=='sidebar' ? $row['content_html'] : NULL; ?></p>
</div>
<?php
}
?>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
fetch
,您仅获取一行;这意味着您必须多次调用 fetch 才能获取所有行。如果您想要一次调用中的所有行,则必须使用
fetchAll
。
With
fetch
, you are only fetching one row ; which means you have to call fetch several times to get all the rows.If you want all the rows in one call, you have to use
fetchAll
.