Search code examples
phpajaxcakephpcakephp-2.x

CakePhp 2.x print sql query On Ajax Request


I am trying to print the mysql query on Ajax Request but it is not showing .

My View Page

enter image description here

Clicking the Search button will call one Ajax Function

Ajax.js

$(document).ready(function(){

function random_number()
{
    return Math.floor(Math.random() * 255);
}
$("#btningSrch").click(function(){
    $("#rpts").html("<img src='https://xx.xx.xx.xx/project/img/ajaxLoader1.gif' />");
    alert("hi");
    $.ajax({
           type: "GET",
           url: "https://xx.xx.xx.xx/project/controller/view/"+random_number(),
           data: "startDate="+$("#startDate").val()+"&type="+$("#type").val()+"&orderby="+$("#orderby").val(),
           dataType: "html",
           success: function(msg){      
                alert(msg);
                $("#rpts").html(msg);
           }
         });
    return false;
  });
});

Controller.php

function show_in_summary()
{
    $this->isLoggedIn();
    //pr($this->request); exit;
    //echo $this->request->is('ajax');
    if ($this->request->is('ajax'))
    {
        //echo 2222; exit; //$this->layout = 'index3';
        //pr($this->InTrafficSummary->txtChk($this->params['url']['startDate']));
        //die();
        //pr($this->request->query);exit;
        //if ($this->InTrafficSummary->txtChk($this->request->query['startDate']))
        //{
            $this->set('record',1);
            $this->loadModel('InOutTrafficSummary');
            $data = $this->InOutTrafficSummary->readInBoundTrafficSummary($this->request->query['startDate'],
            $this->request->query['type'],$this->request->query['orderby']);
            $this->set('reports',$data[0]);
            $this->set('total',$data[1]);
            $this->set('date',date("Y-m-d",strtotime($this->request->query['startDate'])));
            $this->set('type',$this->request->query['type']);
        //}
        //else
        //{
            //$this->set('reports',array());
            //$this->set('record',0);   
            //$this->set('total',array());
            //$this->set('date',date("Y-m-d",strtotime($this->params['url']['startDate'])));
            //$this->set('type',$this->params['url']['type']);
        //}
    }
}               

Model.php

$rs = $this->find('all', array('joins' => array(array(
    'table' => 'InOutTrafficSummary',
    'alias' => 'Carriers',
    'type' => 'INNER',
    'conditions' => array(
     'Carriers.CarrierId = '.$useTable.'.FK_IngressCarrierId'))),
    'conditions' => array('InDate' => date("Y-m-d",strtotime("-1 days"))),
    'fields' => array(
'FK_IngressCarrierId,CarrierName,Sum(TotalCalls),Sum(ConnectedCalls),sum(Duration),(Sum(ConnectedCalls)/Sum(TotalCalls))*100,sum(Duration)/Sum(ConnectedCalls),sum(SaleAmount)'),'group' => 'FK_IngressCarrierId','order' => 'sum(Duration) DESC'));

echo $this->element('sql_dump'); exit;

I want to print the query above as it is not showing any records , i am assuming there is a mistake in the formation so need to view the entire query.All the other things are working fine.

I am a newbie to CakePHP.


Solution

  • Try this

    debug($this->YOUR_MODEL_NAME->getDataSource()->getLog(false, false));