Hello

you can define model association between agent and device and perform find
operation  with condition agents.verified=1only..CakePHP association perfom
internal joining and give you expected result. you can try out with this...

Thanks


On Wed, Jul 22, 2009 at 7:17 PM, mona <poojapinj...@gmail.com> wrote:

>
> How to write the folowing query in cakephp
>
>  $sql = "select
> devices.uid,devices.agent,devices.capabilities,devices.localcaps from
> devices,agents where devices.uid = agents.uid and agents.verified=1
> limit 100";
>
> Followin is my controller file
>
> class AgentsController extends AppController {
>        var $name = 'Agents';
>        var $helpers =
> array('Html','Form','Xml','Text','Javascript','Ajax');
>        var $uses = array( 'Agent','Device');
>        var $components = array('RequestHandler');
>
>
>        function admin_exportDevice(){
>        $this->_adminOnly();
>        $export = trim($this->data['deviceExport']['export']);
>        if($export=='Full'){
>   $sql = "select
> devices.uid,devices.agent,devices.capabilities,devices.localcaps from
> devices,agents where devices.uid =   agents.uid and agents.verified=1
> limit 100";
>  $qry = mysql_query($sql);
>    $this->set('qry', $qry);
>    $this->set('filename', 'Full'.date("Ymd").'.xml');
>    $this->layout='ajax';
>
>        $sql1 = "Update devices set export=1 where export=0";
>        $query = mysql_query($sql1);
>        }
>         else{
>       $sql = "select
> devices.uid,devices.agent,devices.capabilities,devices.localcaps from
> devices,agents where devices.uid = agents.uid and agents.verified=1
> and devices.export=0 limit 2";
>        $qry = mysql_query($sql);
>    $this->set('qry', $qry);
>    $this->set('filename', 'Incremental'.date("Ymd").'.xml');
>    $this->layout='ajax';
>        $sql1 = "Update devices set export=1 where export=0";
>        $query = mysql_query($sql1);
>
>          }
>        }
> }
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to