Php 如何从等于多个值的字段中提取mysql结果
因此,我有一个表,其中有一行包含类别和其他行 因此有:Php 如何从等于多个值的字段中提取mysql结果,php,mysql,sql,Php,Mysql,Sql,因此,我有一个表,其中有一行包含类别和其他行 因此有: id (post id) category (news, videos, music, photos, tutorials, coming-soon, etc..) title (title of post) desc (short meta desc of post) post (the actual post) etc... 比如说,我想做的就是把音乐、视频和照片类别中的所有帖子都拉出来,忽略其他所有内容 我现在的方式是选择WHERE
id (post id)
category (news, videos, music, photos, tutorials, coming-soon, etc..)
title (title of post)
desc (short meta desc of post)
post (the actual post)
etc...
比如说,我想做的就是把音乐、视频和照片
类别中的所有帖子都拉出来,忽略其他所有内容
我现在的方式是选择WHERE category!='新闻和分类!='教程和类别!='很快就来。。。。等等,等等,
但总共有12个类别,这意味着我要做9次
有没有更好的方法来编写WHERE语句,这样就不必引用所有其他语句,而只引用我想要的语句
我尝试了,其中category='videos'和category='music'和category='photos'
,但这似乎不起作用。您想要的逻辑是:
WHERE category = 'videos' OR category = 'music' OR category = 'photos'
更好的是,只需在中使用:
WHERE category IN ('videos', 'music', 'photos')