Re: Query for fetching data from two tables
I see from the error message, that you are making the find in your users controller! Assuming that your users controller is using the User model, the correct find statement should be: [code] $this->User->find( ... [/code] Try changing your find statement, leaving out the Detail model! If it still fails, please include the code for the model associations and the controller in which you are making the find. Enjoy, John On Jan 19, 8:01 am, John wrote: > hello John > thanks for the reply but its showing an error > > Notice (8): Undefined property: AppModel::$User [APP/controllers/ > users_controller.php, line 3493] > > Fatal error: Call to a member function find() on a non-object in /var/ > www/Forex24/app/controllers/users_controller.php on line 3493 > > associations are defined . so can i bind the model in controller only. > > thanks > [snip] Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Re: Query for fetching data from two tables
hello John thanks for the reply but its showing an error Notice (8): Undefined property: AppModel::$User [APP/controllers/ users_controller.php, line 3493] Fatal error: Call to a member function find() on a non-object in /var/ www/Forex24/app/controllers/users_controller.php on line 3493 associations are defined . so can i bind the model in controller only. thanks On Jan 13, 8:44 pm, John Andersen wrote: > I assume that you have defined the following associations/ > relationships in your models: > Detail belongsTo User / User hasMany Details > > If you have the Detail record, then you can make the following query > from the Detail controller side: > [code] > $this->Detail->User->find( > 'all', array( > 'recursive' => 1, > 'conditions' => array( > 'User.id' => $this->data['Detail']['user_id'] > ) > ) > ); > [/code] > > Enjoy, > John > > On Jan 13, 9:51 am, Manu wrote: > > > > > I have two tables details and users . I am getting the Detail.id from > > this i will be able to know User.id and then from users table i have > > to fetch user data like(name, email, etc). so i want to make query in > > cake pattern that in result should give me data of both the table. > > Here's simple query that i have made but couldnt get it going in cake > > pattern. > > > SELECT d.vps_name, d.machine_type, d.ipAddress, d.rdp_user,d.rdp_pass, > > d.dc_user, d.dc_pass, d.status, d.user_id, d.order_id,u.email, > > u.fname, u.lname FROM details as d > > LEFT JOIN users as u > > ON d.user_id = u.id > > WHERE d.user_id = u.id > > > Thanks in advance Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Re: Query for fetching data from two tables
I assume that you have defined the following associations/ relationships in your models: Detail belongsTo User / User hasMany Details If you have the Detail record, then you can make the following query from the Detail controller side: [code] $this->Detail->User->find( 'all', array( 'recursive' => 1, 'conditions' => array( 'User.id' => $this->data['Detail']['user_id'] ) ) ); [/code] Enjoy, John On Jan 13, 9:51 am, Manu wrote: > I have two tables details and users . I am getting the Detail.id from > this i will be able to know User.id and then from users table i have > to fetch user data like(name, email, etc). so i want to make query in > cake pattern that in result should give me data of both the table. > Here's simple query that i have made but couldnt get it going in cake > pattern. > > SELECT d.vps_name, d.machine_type, d.ipAddress, d.rdp_user,d.rdp_pass, > d.dc_user, d.dc_pass, d.status, d.user_id, d.order_id,u.email, > u.fname, u.lname FROM details as d > LEFT JOIN users as u > ON d.user_id = u.id > WHERE d.user_id = u.id > > Thanks in advance Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Query for fetching data from two tables
I have two tables details and users . I am getting the Detail.id from this i will be able to know User.id and then from users table i have to fetch user data like(name, email, etc). so i want to make query in cake pattern that in result should give me data of both the table. Here's simple query that i have made but couldnt get it going in cake pattern. SELECT d.vps_name, d.machine_type, d.ipAddress, d.rdp_user,d.rdp_pass, d.dc_user, d.dc_pass, d.status, d.user_id, d.order_id,u.email, u.fname, u.lname FROM details as d LEFT JOIN users as u ON d.user_id = u.id WHERE d.user_id = u.id Thanks in advance Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Re: How to write one single query for fetching data from two tables
Yes , RWS - Bharat Maheriya is right. If you are writing queries for joins in the fabulous framework like cakephp then what is the need to us the framwork. Cakephp has a good feature of associations so please use that to join the tables. You have to write custom queries only few times & it is negligible. So my suggestion is dont break the rules of the framework. On Mon, Jul 27, 2009 at 11:33 AM, RWS - Bharat Maheriya < rws.bha...@gmail.com> wrote: > 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 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); >> >> } >>} >> } >> >> > > > > -- Thanks & Regards, Vijayk. Co-founder (www.weboniselab.com) "You Bring the Dreams, We'll Bring the Means" --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: How to write one single query for fetching data from two tables
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 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 -~--~~~~--~~--~--~---
How to write one single query for fetching data from two tables
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 -~--~~~~--~~--~--~---