我想从我的 MySQL 中获取数据并仅在$featured == 1
. 它有效,唯一一个$featured == 1
会显示标题,但我的问题是它还会从我数据库中的所有其他内容(空帖子)中发布帖子。我只希望它显示带有 == 1 的帖子,仅此而已。我无法修复它。
<aside id="featured" class="body"><article>
<?php
for ($i=0; $i <$num_results; $i++){
$row1 = $result1->fetch_assoc();
$featured = ($row1['featured']);
if ($featured == 1) {
echo $row1['title'];
} else {
}
?>
<figure>
<img src="images/black2.gif" alt="Black 2" style="width: 300px;"/>
</figure>
<hgroup>
<h2>Featured Article</h2>
<h3><a href="goodies/black2.html">
</a></h3>
</hgroup>
<p> </p>
<footer class="post-info">
<abbr class="published" title="date">20 juli 2012</abbr>
<address class="vcard author">By<a class="url fn" href="portfolio.html">F4LLCON</a>
</address></footer><!-- /.post-info -->
</article>
<?php
}
$result1->free();
?>
</aside><!-- /#featured -->
- 看起来像:
- 但我想要这样: