php - FIND_IN_SET in cakephp not working
问题描述
I have a table in which category ids are stored in the DB as comma separated values, so I need to search another array in this comma separated values.
Need to search $required_ids_array
in Posts.category_ids
$required_ids_array = Array (
[0] => 14
[1] => 15
[2] => 16
[3] => 25
[4] => 35
);
if(isset($required_ids_array)){
foreach ($required_ids_array as $storeId) {
$condition = array ();
$condition ['AND'] ['Post.status']=1;
$blogs = $this->Post->find('all', array(
'conditions' => $condition,
'order' => 'Post.id.DESC',
'limit'=>'4',
'FIND_IN_SET(\''.$storeId.'\',Post.category_ids)')
);
}
Thanks in advance
解决方案
This solution worked for me :)
$blogs = $this->Post->find ( 'all', array (
'conditions' => array (
'Post.status' => 1,
'Post.id !=' => $id,
'FIND_IN_SET(?, Post.category_ids)' => array ($storeId) ),
'limit' => 4,
'order' => 'Blog.modified DESC'
) );
推荐阅读
- google-cloud-platform - 如何连接到 gcloud 实例并在启动时或在一行中连续运行命令
- python - PyQt5低于Qlabel空间宽度
- mysql - MySQL 使用 Group by 和 Order by
- .net-core - 将带有公钥的 .pem 加载到 x509Certificate2
- spring - 将 Spring Boot 从 2.1.4 更新到 2.2.5 后找不到 bean entityManagerFactory
- macos - 如何为 Sublime Text 3 创建永久 subl 链接?(麦克卡特琳娜)
- javascript - 是否有某种role.edit 切换功能?我正在制作一个应该在权限之间切换但似乎无法做到的命令
- c - 使用 for 循环迭代二维数组的时间复杂度是多少?
- macos - 使用 SSH 连接附加到 tmux 会话时如何在我的机器上打开新窗口?
- python - 我的 Python unittest 脚本在 Eclipse PyDev 中失败,但在 Spyder 中有效