在我正在处理的CMS中,我正在使用foreach语句来显示返回的数据库结果。
但是每次页面加载我都会收到一条错误消息,说 im 使用的 foreach 语句具有无效参数
这是声明
<?php foreach ( $presults as $post ) { ?>
<!-- Post Frames -->
<div class="outerPost_frame">
<div class="postScreen">
<!--post date hidden show on hover -->
<span class="date_">
<p><?php echo date('j F', $post->date) ?></p>
</span>
<!-- post title -->
<span class="name_">
<p><?php echo htmlspecialchars($post->name) ?></p>
</span>
<span class="content_">
<?php echo $results['post']->content ?>
</span>
</div>
</div>
<?php } ?>
尝试将$presults转换为数组。
<?php foreach ( (array) $presults as $post ) { ?>
你如何设置你的数组,可能是一个问题,但我们需要一个错误消息才能确定。
试试这个
<?php foreach ( $presults as $post ) { ?>
<!-- Post Frames -->
<div class="outerPost_frame">
<div class="postScreen">
<!--post date hidden show on hover -->
<span class="date_">
<p><?php echo date('j F', $post[date]) ?></p>
</span>
<!-- post title -->
<span class="name_">
<p><?php echo htmlspecialchars($post[name]) ?></p>
</span>
<span class="content_">
<?php echo $post[content] ?>
</span>
</div>
</div>
<?php } ?>