FMFindQuery()

At work we use the very handy FX.php library to develop sites in PHP with FileMaker as the backend. Due to an upcoming change in the way course numbers are represented in our student information system, I needed to ‘extend’ a found set in one of my models. From reading the FX.php documentation, I got the impression that it wasn’t possible to do using FX.php. So, I took a look at the official FileMaker documentation on Custom Web Publishing with XML to see if this was a limitation of FileMaker server, or just something that hadn’t made it into FX.php. What I came across was the ‘-findquery’ and ‘-query’ parameters which allow you to do a “compound find request” (so it is supported!). I couldn’t find anything about how to do this in the FX.php documentation, so I decided that I would take a look at the source code to see if it was there, and if not, make an attempt at adding it.

Turns out there is a function called FMFindQuery that is not in the FXFunctions documentation. It took some trial and error, but I was able to figure out how it worked and wanted to share what I learned. Here is a simple example of the use of FMFindQuery that is analogous to what I was trying to accomplish. According to the official CWP documentation, the ‘-query’ parameter is where you provide the query names and search criteria for your request. Each search request (or set of search requests) should be enclosed in parentheses. AND search requests should be separated by a comma (make sure there are no spaces between your commas, or it won’t work!). OR search requests are separated by semi-colons. You can perform an OMIT request by prefixing your request with an exclamation point like so !(q3). Here is an example:

$InstanceName->AddDBParam(‘-query’, ‘(q1,q2);(q1,q3)’);
$InstanceName->AddDBParam(‘-q1’, ‘PetName’);
$InstanceName->AddDBParam(‘-q1.value’, ‘Spot’);
$InstanceName->AddDBParam(‘-q2’, ‘Breed’);
$InstanceName->AddDBParam(‘-q2.value’, ‘Shiba Inu’);
$InstanceName->AddDBParam(‘-q3’, ‘Breed’);
$InstanceName->AddDBParam(‘-q3.value’, ‘Corgi’);
$ReturnedData = $InstanceName->FMFindQuery();

This request would find all Pets where ‘PetName’ is ‘Spot’ AND ‘Breed’ is ‘Shiba Inu’ OR ‘PetName’ is ‘Spot’ AND ‘Breed’ is ‘Corgi’.

After figuring out how it all worked, I decided to fork the FX.php project on Github and add a section to the FXFunctions.rtf file about FMFindQuery(). Today, I got an email that my change had been merged back into the main FX.php repo. A small contribution, but it is my first contribution to open source software on Github!

FMFindQuery()

Leave a Reply

Your email address will not be published. Required fields are marked *