Yii 条件中的复杂查询
Yii complex query in criteria
我有一个搜索条件。现在我需要一个复杂的查询
如下 MySQL
SELECT id, location_lat, location_lng, ((location_lat - $lat)*(location_lat - $lat) + (location_lng - $lng)*(location_lng - $lng)) as distsqr FROM revite.tbl_event where location_lat is not null and location_lng is not null order by distsqr;
Yii--条件如下
$criteria = new CDbCriteria;
$criteria->addSearchCondition('name', $model->name);
如何将以上 MySQL 查询添加或组合到以上条件中?
请推荐我。
谢谢。
我解决了这个问题
$criteria = new CDbCriteria;
$criteria->addSearchCondition('name', $model->name);
$criteria->addCondition('location_lat is not null and location_lng is not null');
$criteria->order = '(location_lat - :lat) * (location_lat - :lat) + (location_lng - :lng) * (location_lng - :lng)';
$criteria->params[':lat'] = $lat;
$criteria->params[':lng'] = $lng;
我有一个搜索条件。现在我需要一个复杂的查询
如下 MySQL
SELECT id, location_lat, location_lng, ((location_lat - $lat)*(location_lat - $lat) + (location_lng - $lng)*(location_lng - $lng)) as distsqr FROM revite.tbl_event where location_lat is not null and location_lng is not null order by distsqr;
Yii--条件如下
$criteria = new CDbCriteria;
$criteria->addSearchCondition('name', $model->name);
如何将以上 MySQL 查询添加或组合到以上条件中?
请推荐我。
谢谢。
我解决了这个问题
$criteria = new CDbCriteria;
$criteria->addSearchCondition('name', $model->name);
$criteria->addCondition('location_lat is not null and location_lng is not null');
$criteria->order = '(location_lat - :lat) * (location_lat - :lat) + (location_lng - :lng) * (location_lng - :lng)';
$criteria->params[':lat'] = $lat;
$criteria->params[':lng'] = $lng;