0

I need to make this logic in one query.

can anyone help please.

$ids = array('54bcf40b-9c78-4e08-a331-01bc5ab9b466', null, null, null, '54bb94bc-f5c0-4512-a593-01985ab9b466');

foreach ( $ids as $id ) {
    $managers = $this->AccountManager->findByPropertyId($id);
    if (count($managers) > 0) 
        break;
}
?>
Yerko Palma
  • 12,041
  • 5
  • 33
  • 57
  • 1
    You should put a little more information on what you want to achieve. All I can assume here is that you want to get the first id that has managers attached to it? If so, use inner join of both tables and get the first record id. – Skatch Mar 12 '15 at 15:33
  • it's just only one table. i need to get the managers for property_id in this array . but if i got result from the first index of the array then stop the operation else check the next index. – Eng. Alaa Jaddou Mar 12 '15 at 15:40
  • You want to get the first result for any id? And I don't get the point of having three null ids in the hardcoded array. – Skatch Mar 12 '15 at 15:41
  • no i need to get all results starting from the first index if i got results don't check the other indexes if i got nothing i need to check the next index – Eng. Alaa Jaddou Mar 12 '15 at 15:43
  • this array is from variables .. but the values it should be id or null. – Eng. Alaa Jaddou Mar 12 '15 at 15:44
  • take a look at this http://stackoverflow.com/questions/1332434/mysql-order-by-in – Skatch Mar 12 '15 at 15:48
  • not what i want, and not even close – Eng. Alaa Jaddou Mar 12 '15 at 16:00
  • **http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#complex-find-conditions** – ndm Mar 12 '15 at 18:40
  • 1
    And [**filter out**](http://php.net/array_filter) the `null`s if necessary. – ndm Mar 12 '15 at 18:42

0 Answers0