Search using values from a multiple select option
Hi! I have a multiple select option where the use can select 1 or more owners. I need to query the database based on the owners selected. There was an article i read http://groups.google.com/group/cake-php/browse_thread/thread/e6321043e861d1c1/cca8f2f008e7fb32?lnk=gstq=select+multiple+valuesrnum=1#cca8f2f008e7fb32 this is like A or B.What I need is A or B or C or. i.e it depends on the number of owners selected. For example if he selects owner1 and owner2 and enters 1234 as equipment number I need to check if owner1 has 1234 equipment number owner2 has 1234 equipment number i.e owner=owner1 or owner2 I can get the values from the multiple select option array($conditions['owner'] in this case). Im able to get it manually and that too only 1 value. How do I get all the values and place it in the sql? Hoping for some help Thanks! Kashyap --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Search using values from a multiple select option
This might be of use - it shows how to create OR conditions http://groups.google.com/group/cake-php/browse_thread/thread/4c05f96a111f7b33/bf00383ffee075f6?lnk=gstq=findall+%22or%22+%3D%3E+arrayrnum=1#bf00383ffee075f6 On Jun 6, 5:00 pm, hashkash [EMAIL PROTECTED] wrote: Hi! I have a multiple select option where the use can select 1 or more owners. I need to query the database based on the owners selected. There was an article i readhttp://groups.google.com/group/cake-php/browse_thread/thread/e6321043... this is like A or B.What I need is A or B or C or. i.e it depends on the number of owners selected. For example if he selects owner1 and owner2 and enters 1234 as equipment number I need to check if owner1 has 1234 equipment number owner2 has 1234 equipment number i.e owner=owner1 or owner2 I can get the values from the multiple select option array($conditions['owner'] in this case). Im able to get it manually and that too only 1 value. How do I get all the values and place it in the sql? Hoping for some help Thanks! Kashyap --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Search using values from a multiple select option
$owners = array('1','2','3') $equipment = $this-Equipment-findAll( array('Equipment.owner_id'= $owners) ); This will generate WHERE `Equipment`.`owner_id` IN ('1','2','3') which sounds like what you want. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Search using values from a multiple select option
Thanks alot for the help on the OR condtions,but my problem related to the checking the owners is based on the number of owners the user selects.I cant code it directly.Its based on user selection. Any idea? Thanks! Kashyap --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Search using values from a multiple select option
On Jun 6, 9:32 am, hashkash [EMAIL PROTECTED] wrote: Thanks alot for the help on the OR condtions,but my problem related to the checking the owners is based on the number of owners the user selects.I cant code it directly.Its based on user selection. Any idea? don't use an OR and read what Grant Cox kindly already wrote? If that doesn't solve your problem explain why. hth, AD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Search using values from a multiple select option
$owners = array('1','2','3') $equipment = $this-Equipment-findAll( array('Equipment.owner_id'= $owners) ); Correct me if im wrong but from what grant Cox has written I construe that there are only 3 owners. In my case he no of owners keep growing as and when they register. The owners are selected from a multiple select option. Im not using a findAll() but using a query() because when i used the findall()before posting on this group i got a few errors. so im using the query(). Kashyap On Jun 6, 12:37 pm, AD7six [EMAIL PROTECTED] wrote: On Jun 6, 9:32 am, hashkash [EMAIL PROTECTED] wrote: Thanks alot for the help on the OR condtions,but my problem related to the checking the owners is based on the number of owners the user selects.I cant code it directly.Its based on user selection. Any idea? don't use an OR and read what Grant Cox kindly already wrote? If that doesn't solve your problem explain why. hth, AD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Search using values from a multiple select option
here is a part of the controller code http://bin.cakephp.org/view/486635630 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Search using values from a multiple select option
On Jun 6, 9:49 am, hashkash [EMAIL PROTECTED] wrote: $owners = array('1','2','3') $equipment = $this-Equipment-findAll( array('Equipment.owner_id'= $owners) ); Correct me if im wrong but from what grant Cox has written I construe that there are only 3 owners. mmm k. In my case he no of owners keep growing as and when they register. The owners are selected from a multiple select option. rhetoricalAnd in what form is that available to you in the controller. do pr ($this-data['Equipment']['owner']); how does that var change when you select 1, 2 or n owners in your form./rhetorical Im not using a findAll() but using a query() because when i used the findall()before posting on this group i got a few errors. so im using the query(). Well that's one way to avoid being helped. Use findAll and it's simple use query and you are on your own ;). hth, AD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---