Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从联接表进行Cakephp搜索_Php_Mysql_Cakephp_Cakephp 2.0_Cakephp 2.3 - Fatal编程技术网

从联接表进行Cakephp搜索

从联接表进行Cakephp搜索,php,mysql,cakephp,cakephp-2.0,cakephp-2.3,Php,Mysql,Cakephp,Cakephp 2.0,Cakephp 2.3,您好,我正在查询中加入多个表。我想根据我在多个表上检查的搜索关键字获得结果 这是我的密码 public function getGigPostBasedOnSearch($keyword){ $this->Behaviors->attach('Containable'); return $this->find('all', array( 'contain' => array( 'User

您好,我正在查询中加入多个表。我想根据我在多个表上检查的搜索关键字获得结果

这是我的密码

public function getGigPostBasedOnSearch($keyword){
        $this->Behaviors->attach('Containable');
        return $this->find('all', array(

            'contain' => array(
              'User','UserInfo', 'GigPostAndCategory.Category','Location','GigPostAndCalender'

            ),
              'conditions' => array(
                  'AND' => array( 
                      'GigPost.active' => 1,
               'OR' => array(

            array('GigPost.title LIKE' => '%'.$keyword.'%'),
            array('GigPost.description LIKE' => '%'.$keyword.'%'),
            array('Location.location_string LIKE' => '%'.$keyword.'%'),


        )
)
                 //'OrderGigPost.request' => 0
            ),
            'order' => 'GigPost.gig_post_id DESC',

            'recursive' => 0
        ));
    }
查询成功,并得到我想要的结果。但是在同一个查询中,我还想在类别表中搜索。但如果我这样做了

array('Category.cat_name LIKE' => '%'.$keyword.'%')
我得到一个sql错误,它说找不到列名

类别表有两列
cat\u id
cat\u name

GigPostAndCategory
id
cat\u id
gig\u post\u id
(因为一个
gigpost
可以有多个类别,所以我为其制作了一个单独的表格)


因此,我还需要帮助根据类别获取结果如果搜索的关键字与类别中的某个内容匹配

当您“包含”数据时,它通常会运行单独的查询,然后将其组合在一起返回给您

因此,您不能对包含的表运行条件(取决于某些因素,但最好假设您不能)

相反,使用连接。这将确保它被拉入同一个查询,并允许您访问联接表字段


(提示:您可以在DebugKit中查看正在运行的查询。这通常会为您提供所需的线索,以了解其不起作用的原因。)

谢谢@dave。。。如果可能的话,你能用join来写这个查询吗?我是新手,我只知道这个方法