如何将WHERE语句添加到此SQL查询

时间:2015-10-05 16:30:07

标签: php mysql

我正在尝试向此查询添加where语句,因此它只显示已设置为已发布的记录。

$query = "SELECT id, heading, summary, date, keyword1, keyword2, keyword3
     FROM " . DB_TABLE . "";

我试过

$query = "SELECT id, heading, summary, date, keyword1, keyword2, keyword3, publish
     WHERE publish ='y' FROM " . DB_TABLE . "";

$query = "SELECT `id`, `heading`, `summary`, `date`, `keyword1`, `keyword2`, `keyword3`, `publish`
   WHERE `publish` ='y' FROM " . DB_TABLE . "";

但是他们似乎都没有工作,任何帮助都非常感谢,谢谢

1 个答案:

答案 0 :(得分:3)

这个怎么样:

$query = "SELECT `id`, `heading`, `summary`, `date`, `keyword1`, `keyword2`, `keyword3`, `publish` FROM " . DB_TABLE . " WHERE `publish` ='y' ";

如果您查看MySQL documentation,您会看到SELECT语句首先出现,然后FROM语句和WHERE最后出现。当然可以使用其他各种语句,您可以在上面的链接中找到所有这些语句