1 Reply Latest reply on Mar 8, 2011 4:31 PM by shudder

    Using PHP to 'Find' data in FMP



      Using PHP to 'Find' data in FMP


      Hello Folks --

      I am working on my first FMP PHP Assistant generated php site.  We are in the process of web-enabling all services for one of our departments, and this includes a couple of older FMP files.  Everything is currently running on our FMP 10 server with PHP 5.2.6 installed.  Clients are using a mix of FMA 11 and FMA10.  Mac OSX (Snow Leopard).

      Generating the PHP files with the assistant app was simple and easy.  I generated a full site using the included Linea template and then started making minor UI tweaks to suit our needs (swapping graphics and colors, etc.).  That all worked out well, but then I ran into an issue with the report.php or summary.php files.

      The report apparently returns ALL records.  We do not want ALL records: We need active records in the system, so I need to OMIT out all Status = 'Completed' records.  This is simple enough to do in FMP itself with a simple script (see below), but I can't seem to figure out how to make this happen via PHP calls in the web browser.  The PHP files are still a bit opaque to me (sorry, still coming up to speed on PHP nomenclature in general…).

      Here's the total of the very simple "Refresh" script in the user's call log:

      Set Error Capture [On]

      Enter Browse Mode []

      Go To Layout["Main Screen" (Call Log)]

      Perform Find [Restore]

      If [Get (LastError)=401]

        Show Custom Dialog ["All Call Completed"; "TEXT OF DIALOG HERE..."]

        Adjust Window [Resize to Fit]

        Halt Script

      End If

      Sort Records [Restore; No dialog]

      Go to Record/Request/Page [First]

      Adjust Window [Resize to Fit]

      Nothing extraordinary in there at the least.  The Restored Find in the script above has one simple search criteria:

      Omit Records -- Call Log::Status: [Completed]

      So, running the Refresh script returns any open call -- that is, any call not marked Status = 'Completed' (of course, the vast majority of calls in the system are Completed -- we do not need to see them in any of the report screens in the browser, but retain them for future use in the system).

      What's the best way to approach this, please?  I am completely new to PHP, but am trying to learn quickly.

      Do I need to call the Refresh script from my FMP db via PHP, or can I alter what is returned to the report page from the DB via tweaks to the PHP code on the summary.php or report.php pages?

      Thank you in advance for shedding light on this for me.

      - shudder

        • 1. Re: Using PHP to 'Find' data in FMP

          Hi Folks --


          I might have solved this.  Pretty unsiure if this is the best way to go about this, but it seems to work...

          I attacked it in the report.php file.  In there is the code for finding the target records:


          // perform the find

          $result = $findCom->execute();



          I commented this out and replaced it with a compoundFind object that I gleaned from documentation.  I would rather do a simple, straightforward Find, but could not figure out how to instantiate an OMIT within the find schema (dang it!), so I wound up using the compoundFind, finding for all iterations of the Status field EXCEPT Status = Completed.  I wrote this:


          // Create the compoundFind command object:

          $compoundFind =& $fm->newCompoundFindCommand($layoutName);

          $findreq1 =& $fm->newFindRequest($layoutName);

          $findreq2 =& $fm->newFindRequest($layoutName);

          $findreq3 =& $fm->newFindRequest($layoutName);

          $findreq4 =& $fm->newFindRequest($layoutName);

          // Create Find request 1-4:

          $findreq1->addFindCriterion('Status', 'In');

          $findreq2->addFindCriterion('Status', 'Returned');

          $findreq3->addFindCriterion('Status', 'Left Word');

          $findreq4->addFindCriterion('Status', 'NTC/Do');

          //  Specify search criterion for all requests:





          // Execute the compoundFind command:

          $result = $compoundFind->execute();


          Bulky, but that got me what I wanted -- that is, all calls EXCEPT Status = Completed

          Now I just need to figure out how to swap the sort to put most recent calls at the top instead of the bottom, and how to make the caller's name a clickable object so I can take the user over to that call without having to look at it here, and then go to the Find screen and perform a separate find for it there.  That's a pain...

          - shudder