4 Replies Latest reply on Jan 4, 2012 9:21 AM by beverly

    PHP API range search tip

    mbraendle

      Hi,

       

      just a short tip about range searching with the FM PHP API.

       

      Example: I want to search records where the values of the field "field" are in the range 3-20.

       

      This does not work:

       

      $min_range = 3;

      $max_range = 20;

      $findRange = $fm->newFindCommand('your_layout');

      $findRange->addFindCriterion('field', FILEMAKER_FIND_GTE.$min_range);

      $findRange->addFindCriterion('field', FILEMAKER_FIND_LTE.$max_range);

      $result = $findRange->execute();

       

      The second find criterion overwrites the first one, yielding all records that have values from -infinity to 20.

       

       

      It works, however, with newCompoundFindCommand(), which simulates the query as you would have created in FM directly:

       

      $min_range = 3;

      $max_range = 20;

      $findRange = $fm->newCompoundFindCommand('your_layout');

      $findrequest1 = $fm->newFindRequest('your_layout');

      $findrequest1->addFindCriterion('field', $min_range . '...' . $max_range);

      $findRange->add(1,$findrequest1);

      $result = $findRange->execute();

       

      Cheers,

       

      Martin