I use YII as the PHP framework. One of the functions is to query people nearby. My code does this: {code...} I use Mysql to calculate the distance. But when I print it out, I find that the distance attribute is not: {code...} That is, Yii only uses the YII in the user table as the PHP framework. One of the functions is to query people nearby.
My code does this:
Class NearByController extends Controller {// someone nearby is found. No filtering is available. Where is distance? Public function actionIndex () {$ latitude = UserRefreshForm: model ()-> getLatitude (); $ longdistance = UserRefreshForm: model ()-> getlongdistance (); $ criteria = new CDbCriteria (); $ nearPersons = MGetNear: getNearPersonsNoOrder (); $ criteria-> select ='t. *, (ACOS (SIN (('. $ latitude. '* 3.1415)/180) * SIN (tbl_myr_refresh.latitude * 3.1415)/180) + COS (('. $ latitude. '* 3.1415)/180) * COS (tbl_myr_refresh.latitude * 3.1415)/180) * COS (('. $ longpolling. '* 3.1415)/180-(tbl_myr_refresh.long1_* 3.1415)/180) * 6378.137) as distance'; $ criteria-> join = 'left JOIN tbl_myr_refresh ON tbl_myr_refresh.userId = t. userid'; $ criteria-> addInCondition ('t. userid', $ nearPersons); $ criteria-> order = 'distance ASC '; $ UserModel = User: model (); $ total = $ UserModel-> count ($ criteria); $ pager = new CPagination ($ total); $ pager-> pageSize = 10; $ pager-> applyLimit ($ criteria); $ userList = $ UserModel-> findAll ($ criteria); p ($ userList );}
I use Mysql to calculate the distance.
But when I print it out, I find that there is no distance attribute:
Array ([0] => User Object ([password1] => [password2] => [geohash] => [_ new: CActiveRecord: private] => [_ attributes: CActiveRecord: private] => Array ([userId] => 3 [username] => [password] => c3284d0f94606de1fd2af172aba15bf3 [email] => 741691740@qq.com [phoneNumber] => [birthday] => [gender] => 1 [homeland] => Sichuan Nanchong [wantWhere] => [registerDate] => 2014-06-27 [smallAvatar] => region [bigAvatar] => region [qrcode] => [isStudent] => 1 [wentWhere] => [md5] => role [sessionId] => o5fcapmo7clfiiua717n1aa525 [iemi] => 123456789) [_ related: CActiveRecord: private] => Array () [_ c: CActiveRecord: private] => [_ pk: CActiveRecord: private] => 3 [_ alias: CActiveRecord: private] => t [_ errors: CModel: private] => Array () [_ validators: CModel: private] => [_ scenario: CModel: private] => update [_ e: CComponent: private] => [_ m: CComponent: private] => ))
That is, Yii only prints out some of the user tables. However, the distance attribute is not printed!
For help. YII tells me how to obtain this distance attribute?
Reply content:
I use YII as the PHP framework. One of the functions is to query people nearby.
My code does this:
Class NearByController extends Controller {// someone nearby is found. No filtering is available. Where is distance? Public function actionIndex () {$ latitude = UserRefreshForm: model ()-> getLatitude (); $ longdistance = UserRefreshForm: model ()-> getlongdistance (); $ criteria = new CDbCriteria (); $ nearPersons = MGetNear: getNearPersonsNoOrder (); $ criteria-> select ='t. *, (ACOS (SIN (('. $ latitude. '* 3.1415)/180) * SIN (tbl_myr_refresh.latitude * 3.1415)/180) + COS (('. $ latitude. '* 3.1415)/180) * COS (tbl_myr_refresh.latitude * 3.1415)/180) * COS (('. $ longpolling. '* 3.1415)/180-(tbl_myr_refresh.long1_* 3.1415)/180) * 6378.137) as distance'; $ criteria-> join = 'left JOIN tbl_myr_refresh ON tbl_myr_refresh.userId = t. userid'; $ criteria-> addInCondition ('t. userid', $ nearPersons); $ criteria-> order = 'distance ASC '; $ UserModel = User: model (); $ total = $ UserModel-> count ($ criteria); $ pager = new CPagination ($ total); $ pager-> pageSize = 10; $ pager-> applyLimit ($ criteria); $ userList = $ UserModel-> findAll ($ criteria); p ($ userList );}
I use Mysql to calculate the distance.
But when I print it out, I find that there is no distance attribute:
Array ([0] => User Object ([password1] => [password2] => [geohash] => [_ new: CActiveRecord: private] => [_ attributes: CActiveRecord: private] => Array ([userId] => 3 [username] => [password] => c3284d0f94606de1fd2af172aba15bf3 [email] => 741691740@qq.com [phoneNumber] => [birthday] => [gender] => 1 [homeland] => Sichuan Nanchong [wantWhere] => [registerDate] => 2014-06-27 [smallAvatar] => region [bigAvatar] => region [qrcode] => [isStudent] => 1 [wentWhere] => [md5] => role [sessionId] => o5fcapmo7clfiiua717n1aa525 [iemi] => 123456789) [_ related: CActiveRecord: private] => Array () [_ c: CActiveRecord: private] => [_ pk: CActiveRecord: private] => 3 [_ alias: CActiveRecord: private] => t [_ errors: CModel: private] => Array () [_ validators: CModel: private] => [_ scenario: CModel: private] => update [_ e: CComponent: private] => [_ m: CComponent: private] => ))
That is, Yii only prints out some of the user tables. However, the distance attribute is not printed!
For help. YII tells me how to obtain this distance attribute?
(ACOS(SIN(('.$latitude.'* 3.1415) / 180 ) *SIN((tbl_myr_refresh.latitude * 3.1415) / 180 ) +COS(('.$latitude.'* 3.1415) / 180 ) * COS((tbl_myr_refresh.latitude * 3.1415) / 180 ) *COS(('.$longitude .'* 3.1415) / 180 - (tbl_myr_refresh.longitude * 3.1415) / 180 ) ) * 6378.137) as distance
The alias must be borrowed from an existing field in the table. Otherwise, the value cannot be obtained from the row object.