[英]How to select with array values in comma separated values in mysql
I'm not good at english so i appologise it for first. 我的英语不好,所以我首先道歉。 I have an array value like this: 我有一个像这样的数组值:
$a=['php','java','.Net']
please look at this link provided. 请查看提供的此链接。
http://sqlfiddle.com/#!9/2c07a/4 http://sqlfiddle.com/#!9/2c07a/4
How to make selection with the table. 如何通过表格进行选择。
Please help me guys...I thank you in advance... 请帮助我...我先谢谢你...
Use FIND_IN_SET
使用FIND_IN_SET
PHP code: PHP代码:
$a=['php','java','.Net']
$query_part = '';
foreach($a as $v)
{
$query_part .= "FIND_IN_SET('$v',keyskills) OR ";
}
$query_part = trim($query_part, ' OR ');
$sql = "select jobid from jobfair where $query_part";
//select jobid from jobfair where FIND_IN_SET('php',keyskills) OR FIND_IN_SET('java',keyskills) OR FIND_IN_SET('.Net',keyskills);
If you want to return rows that match all values then use AND
clause. 如果要返回匹配所有值的行,请使用AND
子句。
Reference: https://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set 参考: https : //dev.mysql.com/doc/refman/5.0/zh-CN/string-functions.html#function_find-in-set
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.