我有一个搜索条件。现在我需要一个复杂的查询
如下面的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查询添加或组合成上述标准?
请建议我。
谢谢。
答案 0 :(得分:1)
我解决了这个问题
$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;