3 Replies Latest reply on Jul 14, 2017 8:20 AM by mikebeargie

    Fetch all records giving me the same record multiple times

    divya

      I am using php with filemaker when I do fetch all records

       

      $findCom =& $fm->newFindCommand('Product');

      $result = $findCom->execute();

      $records = $result->getRecords();

       

      giving me the all the records, but first record is repeatedly coming

       

      Please help me out, new to filemaker

        • 1. Re: Fetch all records giving me the same record multiple times
          mikebeargie

          Fetch all records is newFindAllCommand(), not newFindCommand(). If you run newFindCommand without setting any search parameters, you might see odd results.

           

          If you need to set a search parameter, it's done like this:

          $findCommand = $fm->newFindCommand('Form View');

          $findCommand->addFindCriterion('Some Field in Form View', 'Search For This');

          $result = $findCommand->execute();

           

          Please make sure to read through the CWP guide since you are new to the platform:

          https://fmhelp.filemaker.com/docs/16/en/fms16_cwp_guide.pdf

          1 of 1 people found this helpful
          • 2. Re: Fetch all records giving me the same record multiple times
            divya

            Hi Mike,

             

            I tried newFindAllCommand() , but still has same issue.

             

            Please help me what Am I doing wrong

             

             

            $findCom =& $fm->newFindAllCommand('Product');

            $result = $findCom->execute();

            $product_list = array();

            if (FileMaker::isError($result))

            {  

            echo $result->getErrorString();

            exit;

            }

            $records = $result->getRecords();

            • 3. Re: Fetch all records giving me the same record multiple times
              mikebeargie

              Don't use &= on your first line, it's a new command, not appending it to another command, so just:

              $findCom = $fm->newFindAllCommand('Product');

              Every single field on your "Product" layout will be returned. This INCLUDES any related data. You may be seeing repeating data due to having related fields on that layout.

               

              I always create isolated layouts specifically for working with CWP data. FileMaker users never see these, and my PHP/CWP privilege set is isolated to only be allowed to interface with these layouts.

               

              Create a new layout called "ProductCWP", then just put one or two fields, like Product ID/Serial Number and Name from your product table there for testing.

               

              Now update your first line of code to:

              $findCom = $fm->newFindAllCommand('ProductCWP');

              And then add something like this to your test page to output the result:

              foreach ( $records as $rec ) {

                   //SUBSTITUTE YOUR OWN FIELD NAMES BELOW

                   echo "<li>". $rec->getField('Product ID') . " - " . $rec->getField('Product Name') . "</li>";

              }

              This should leave you with an html list like so:

              • 1 - Product 1
              • 2 - Product 2
              • 3 - Another Product
              • etc...
              1 of 1 people found this helpful