加入查询使用两个表,其中条件在cake php?

编程入门 行业动态 更新时间:2024-10-26 02:30:24
本文介绍了加入查询使用两个表,其中条件在cake php?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们如何使用两个表格来处理连接查询,其中条件在cake php?

How we can write Join query using two table with where condition in cake php?

推荐答案

> 如果能帮助你,请检查这个

You can!! check this if it would help you

$table = 'table_name'; $query['conditions'] = array($table.'.entity_id' => $entity_id, $table.'.is_active' => 1); $query['fields'] = array('creator.first_name AS cf_name', 'creator.last_name AS cl_name', 'creator.email AS c_email', 'usr.first_name', 'usr.last_name', $table.'.id AS id', $table.'.guid', $table.'.updated_date', 'usr.email AS email'); // To do joining to get attribute with value $query['joins'] = array( array( 'table' => $this->user, 'alias' => 'usr', 'type' => 'INNER', 'conditions' => array('usr.id = '.$table.'.user_id') ), array( 'table' => $this->user, 'alias' => 'creator', 'type' => 'INNER', 'conditions' => array('creator.id = '.$table.'.creator_id') ), ); $query['order'] = array($table.'.updated_date' => 'DESC'); // Cache implementation $result = $this->find('all', $query);

更多推荐

加入查询使用两个表,其中条件在cake php?

本文发布于:2023-10-30 12:06:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1542801.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条件   两个   php   cake

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!