php Mysql AND WHERE 选择
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18337118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mysql AND WHERE selection
提问by Kenny Bloem
i have te make a slection but cannot get it to work with the WHERE LIKE function. What is wrong with the line below?
我让你做一个选择,但不能让它与 WHERE LIKE 功能一起工作。下面的行有什么问题?
$result = mysql_query("SELECT * FROM games WHERE soort='nieuws' AND gamenaam='$spelnaam' AND platform LIKE '%wiiu%' AND ORDER BY id DESC");
It worked until i added
它一直有效,直到我添加
AND platform LIKE '%wiiu%'
The platform column contains cells with multiple values that come from a selection box form. So it writes, wiiu, ps4, xbox360, pc etc....Must be simple but i tried like a million times...
平台列包含具有来自选择框表单的多个值的单元格。所以它写道,wiiu,ps4,xbox360,pc 等等......一定很简单,但我尝试了一百万次......
回答by karthikr
Remove the AND
before ORDER BY
删除AND
之前的ORDER BY
$result = mysql_query("SELECT * FROM games WHERE soort='nieuws' AND gamenaam='$spelnaam' AND platform LIKE '%wiiu%' AND ORDER BY id DESC");
should be
应该
$result = mysql_query("SELECT * FROM games WHERE soort='nieuws' AND gamenaam='$spelnaam' AND platform LIKE '%wiiu%' ORDER BY id DESC");
回答by Amit Malakar
please don't use mysql_* as it's deprecated, use mysqli_ or PDO instead.
ref to http://php.net/manual/en/book.mysqli.php
请不要使用 mysql_*,因为它已被弃用,请改用 mysqli_ 或 PDO。
参考http://php.net/manual/en/book.mysqli.php
and change your query to
并将您的查询更改为
SELECT * FROM games
WHERE soort='nieuws'
AND gamenaam='$spelnaam'
AND platform LIKE '%wiiu%'
ORDER BY id DESC"
回答by Cobra_Fast
There is an extra AND
, it should be:
还有一个额外的AND
,应该是:
$result = mysql_query("SELECT * FROM games WHERE soort='nieuws' AND gamenaam='$spelnaam' AND platform LIKE '%wiiu%' ORDER BY id DESC");
回答by jterry
SELECT * FROM games
WHERE soort = 'nieuws'
AND gamenaam = '$spelnaam'
AND platform LIKE '%wiiu%'
ORDER BY id DESC
There should not be an AND
before an ORDER BY
statement.
不应该有一个AND
beforeORDER BY
声明。
Also, I feel the obligatory urge to ask that you look into using mysqli
or PDO
instead of mysql
functions, as mysql
is deprecated.
此外,我觉得有必要要求您考虑使用mysqli
或PDO
代替mysql
函数,因为mysql
已弃用。
回答by M Shahzad Khan
$result = mysql_query("SELECT * FROM games WHERE soort='nieuws' AND gamenaam='$spelnaam' AND platform LIKE '%wiiu%' ORDER BY id DESC");
You hav extra 'AND' at the end
最后有额外的“AND”
回答by Harshal Mahajan
It should be like :
它应该是这样的:
$result = mysql_query("SELECT * FROM games WHERE soort='nieuws' AND gamenaam='$spelnaam' AND platform LIKE '%wiiu%' ORDER BY id DESC");
回答by Jeroen van den Broek
You really should not put comma separated values in a field. You actually provided a good example of why not by saying you've got console names in there. What if you're looking for something related to the original Wii? You'd have something like WHERE soort LIKE "%wii%"
, right? Well, this would also return all WiiU related items, because "WiiU" is also LIKE "%wii%".
您真的不应该在字段中放置逗号分隔值。你实际上提供了一个很好的例子,说明为什么不说你有控制台名称。如果您正在寻找与原始 Wii 相关的东西怎么办?你会有类似的东西WHERE soort LIKE "%wii%"
,对吧?嗯,这也将返回所有与 WiiU 相关的项目,因为“WiiU”也像“%wii%”。
The proper way to do this involves making and joining a link table.
正确的方法是制作和加入链接表。