[英]Mysql join tables query in CakePhp
您好,以下是我的表格及其之间的关系
GigPost
位置
GigPost类别
我像这样在GigPost表中查询
public function getAllGigPosts(){
$this->Behaviors->attach('Containable');
return $this->find('all', array(
'contain' => array(
'User', 'GigPostAndCategory.Category','Location'
),
'order' => 'GigPost.gig_post_id DESC',
'recursive' => 0
));
}
}
如果我运行以上查询,这是打印出来的结果
Array
(
[0] => Array
(
[GigPost] => Array
(
[gig_post_id] => 49
[user_id] => 31
[description] => gig post description
[deadline] => 2017-03-14 17:56:37
[pay] => 100
[type_of_payment] => 1
)
[User] => Array
(
[user_id] => 31
[email] => demo@demo.com
[active] => 1
)
[UserInfo] => Array
(
[user_id] => 31
[first_name] => john
[last_name] => doe
[phone_no] => 2147483
[about] =>hello I am john doe
[profile_img] => app/webroot/uploads/31/58b66b8605412test.png
[registration_date] => 2017-02-22 03:40:51
[device_token] => asdsadas
[available_for_gigs] => 1
)
[Location] => Array
(
[gig_post_id] => 49
[lat] => 28.6619
[long] => 77.2274
[city] => Delhi
[state] => India
[country] => India
[location_string] => Delhi, India
)
[GigPostAndCategory] => Array
(
[0] => Array
(
[gigpost_category_id] => 61
[gig_post_id] => 49
[cat_id] => 7
[Category] => Array
(
[cat_name] => clothes
)
)
[1] => Array
(
[gigpost_category_id] => 62
[gig_post_id] => 49
[cat_id] => 1
[Category] => Array
(
[cat_name] => delivery
)
)
)
)
现在,我想获得距离100英里的那些演出岗位。 我有一个SQL查询,它找到两个纬度/长点之间的距离是这个
SELECT
*,
( 3959 * acos( cos( radians(42.290763) ) * cos( radians( location.lat ) )
* cos( radians(location.long) - radians(-71.35368)) + sin(radians(42.290763))
* sin( radians(location.lat)))) AS distance
FROM location
WHERE active = 1
HAVING distance < 100
ORDER BY distance;
问题是我想在上面的查询中合并此查询,以便它也将获取所有这些相关的表数据。 我不知道如何在上面编写的Cakephp查询中执行此查询。
请按照下面的波纹管连接两个桌子
$this->yourtablename->find("all", array(
'joins' => array(
array(
'table' => 'anotherTableName',
'alias' => 'aliasname',
'conditions' => array("WHERE contition")
),),
"fields" => array($fields),
"conditions" => array($commonContion),
"group"=>"ifyou have any group bya",
)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.