我的数据库存在问题。我不知道如何找到包含特定INT的SQL行。我有一个新闻列表,如果这个消息是发布的,则INT是1.这是我的代码:
$base = $db->query('SELECT id, title, image, content, date, slug, publish FROM articles ORDER BY id DESC');
while($row = $base->fetch()) {
if ($row['publish'] == 1) {
/* NEWS */
}
}
提前感谢您的回复。
答案 0 :(得分:2)
在MySQL查询中添加where
publish = 1: -
$base = $db->query('SELECT id, title, image, content, date, slug,
publish FROM articles where publish=1 ORDER BY id DESC');
不需要这种情况: -
if ($row['publish'] == 1)
答案 1 :(得分:1)
无需办理登机手续while()
,仅在select
中添加条件。
$base = $db->query('SELECT id, title, image, content, date, slug, publish
FROM articles WHERE publish = 1 ORDER BY id DESC');
^ ^