Hi all,
I’m having trouble getting this working properly.
Im using CSqlDataProvider to select a number of houses closest from a latitude/longitude.
It’s all working fine except the pagination doesn’t happen properly.
The pagination shows the correct number of pages but each page shows every single house instead of what i’ve specified.
here is some relevant code:
// Select count of below query
$countSql=Yii::app()->db->createCommand(‘SELECT count(*) FROM (SELECT *,( 3959 * acos( cos( radians(’.$center_lat.’) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(’.$center_lng.’) ) + sin( radians(’.$center_lat.’) ) * sin( radians( latitude ) ) ) ) AS distance FROM tbl_forsale HAVING distance < ‘.$radius.’ ORDER BY distance) AS T;’)->queryScalar();
// Get the listings
$sql=‘SELECT * FROM (SELECT *,( 3959 * acos( cos( radians(’.$center_lat.’) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(’.$center_lng.’) ) + sin( radians(’.$center_lat.’) ) * sin( radians( latitude ) ) ) ) AS distance FROM tbl_forsale HAVING distance < ‘.$radius.’ ORDER BY distance) AS T;’;
$dataProvider=new CSqlDataProvider($sql, array(
‘totalItemCount’=>$countSql,
'sort'=>array(
'attributes'=>array(
'price', 'distance',
),
),
‘pagination’=>array(
'pageSize'=>5,
),
));
$this->widget(‘zii.widgets.CListView’, array(
'dataProvider'=>$dataProvider,
'emptyText'=>'There are 0 listings in view.',
'enablePagination'=>true,
'enableSorting'=>false,
'id'=>'list-view-listings',
'itemView'=>'_list',
'template'=>'{sorter}{items}{pager}',
'htmlOptions'=>array('class'=>'list-view-listings'),
));
Any help would be appreciated thx