Activequery

Hallo,

i am searching for help here… was using this little mess query like below.

it is giving right result, the problem is paging is not working. on second page its giving me same result again and again.

Can someone Help me here please. Thank you




Angebote::findBySql('query‘)




$dataProvider = new ActiveDataProvider([

            'query' => $query,

	    'pagination' => [

	    'pageSize' => 10,

	],

        ]);






SELECT *,

  (SELECT ACOS(SIN(RADIANS('Userlat')) * SIN(RADIANS(lat)) 

  + COS(RADIANS('Userlat')) * COS(RADIANS(lat)) * COS(RADIANS(lng) 

  - RADIANS('Userlng'))) * 6371 AS distance

   FROM profile_filialen AS pf

   LEFT JOIN angebot_filialen AS af ON af.filialen_id = pf.id

   WHERE af.angebot_id = aa.id

   ORDER BY distance LIMIT 1) distance

FROM angebote AS aa

WHERE von < UNIX_TIMESTAMP()

  AND bis > UNIX_TIMESTAMP()

  AND status = 1

HAVING (distance < 'umkreis'

        OR distance <= aa.radius

        OR ONLINE = 1)



I think you have 2 options.

  1. Construct the query object for the ActiveDataProvider without using ActiveRecord::findBySql().

That is, you have to construct the query object using the methods of Query or ActiveQuery: select(), join(), where(), having(), … etc, without specifying the final SQL by yourself. Then, ActiveDataProvider will be able to apply offset() and limit() to the query object depending on the pagination.

The query object created by ActiveRecord::findBySql() can not be modified any further.

http://www.yiiframework.com/doc-2.0/yii-db-activerecord.html#findBySql()-detail

  1. Use SqlDataProvider instead of ActiveDataProvider.

http://www.yiiframework.com/doc-2.0/guide-output-data-providers.html

thank you.

i Chosed the second option. :D