php - CakePHP order not working -
hi using cakephp version - 2.5.5.
i have table name chat_ategory_mages
want average number of frequency order descending. know frequency please check - how average hits between current date posted date in mysql?
chat_ategory_mages
id chat_category_id hits created ------------------------------------------------ 1 5 10 2014-11-07 11:07:57 2 5 8 2014-11-10 05:10:20 3 5 70 2014-10-04 08:04:22
code
$order=array('frequency' => 'desc'); $fields=array( 'chatcategoryimage.id', 'chatcategoryimage.chat_category_id', 'chatcategoryimage.created', 'chatcategoryimage.hits', 'hits/(datediff(now(),created)) frequency', );
query-1
$rndqry=$this->chatcategoryimage->find('all',array('conditions'=>array('chatcategoryimage.chat_category_id'=>$cetegory_id), 'fields'=>$fields, 'order'=>$order, 'limit'=>10)); pr($rndqry); //working fine
query-2
//this not working $this->paginator->settings = array( 'conditions'=>array('chatcategoryimage.chat_category_id'=>$cetegory_id), 'fields'=>$fields, 'limit' => 10, 'order' => $order, ); $getcategoryimages = $this->paginator->paginate('chatcategoryimage'); pr($getcategoryimages); //not working
above table if write simple cakephp query order
working fine when using cakephp pagination not working. if using $order=array('hits' => 'desc');
woring perfect. showing result 70,10,8 consistently when adding frequency
result not coming descending order.
mysql query
query-1 :
select chatcategoryimage
.id
, chatcategoryimage
.chat_category_id
, chatcategoryimage
.hits
, chatcategoryimage
.created
, hits/(datediff(now(),created)) frequency, myshowcam
.chat_category_images
chatcategoryimage
chatcategoryimage
.chat_category_id
= 5 order frequency
desc limit 10
query-2 :
select chatcategoryimage
.id
, chatcategoryimage
.chat_category_id
, chatcategoryimage
.hits
, chatcategoryimage
.created
, hits/(datediff(now(),created)) frequency, myshowcam
.chat_category_images
chatcategoryimage
chatcategoryimage
.chat_category_id
= 5 limit 10
what problem , why not coming order frequency
in sec query?
thanks chinu
you can utilize virtualfields
$this->chatcategoryimage->virtualfields = array('frequency' => 'hits/(datediff(now(),created))');
changing way of order
$order = array('frequency' => 'desc');
php mysql cakephp
No comments:
Post a Comment