Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Can I perform an 'If Count' before a result is executed?

Featured Replies

I have lots of searchs that may return 'no records'.  Is there coding that will not kill other php requests on the same page?  Can I make an If statement that will search my db for a count of records before a result is executed:  something like

if ($_Get Count($field == 1)

my field is 'lafall1'.  it is a tennis tournament.  when someone clicks 'yes' for lafall1, it returns the number '1'.  this way, when someone plays 'lafall1', lafall2 and la fall3', a calculation field returns that 3 tournaments have been played.  If no one has clicked 'yes' for 'lafall1', the query will return an error: no records match this request.  It stops the script and  the coding on the rest of my page dies.  Here is a snippet of my code.  Thanks!


<?php
$RandyFind = $fm->newFindCommand('mylayout');
$RandyFind->addFindCriterion('lafall1', '1');
$RandyFind->addSortRule('ssvm', 1, FILEMAKER_SORT_DESCEND);

$RandyFind->setRange(0,500);
$result = $RandyFind->execute();

if (FileMaker::isError($result)) {
    echo($result->getMessage());
    exit;
}

?>

 

<?php

$found = $result->getFoundSetCount();
if($found == 0)
    {
    $record_count = '';
    }
    elseif($found >= 2)
    {
    $record_count = '(' . $found . ' players)';
    }

echo $record_count;?>

 

 

I have never used phpFileMaker, however I have spent about 15 years( or is it 17 by now? ) doing FX.php, pyFileMaker, and regular FileMaker XML queries, with and without XSLT.

I would say this is a fault in FileMaker, a resultset with 0 rows as row count is a valid resultset in most other databases, however FileMaker tells you that it's and error; it's a notification at best.

And the only thing you have to do is modify your code slightly to avoid that error that is not an error, for example like this:

<?php
$q = $fm->newFindCommand( 'mylayout' );
$q->addFindCriterion(     'lafall1',
                          '1' );
$q->addSortRule(          'ssvm',
                           1,
                           FILEMAKER_SORT_DESCEND );

$q->setRange( 0, 500 );
$r = $q->execute();

if( FileMaker::isError( $r ) ) {
  if( $r->code != 401 ) {
    echo( $r->getMessage() );
    exit;
  } else {
    /* Some magic stuff here that will tell your user that there was no records found using that search criteria, 
       or ideally the code generating your output should handle this part with and if or a case */
  }
}
?>

Edited by ggt667

  • Author

Thanks ggt667, I'm gonna try some kind of workaround, I appreciate your efforts!

  • Author

Hi, I have field that are tournaments, people click yes or no to join.  yes = 1 and no = 0.  When search results says 'No Matching Records', it stops all PHP and html past that point.  Is there a workaround for that?  Is there an IF statement I can use to check if anyone has clicked yes or no for a particular field before it executes and returns 'No Matching Records'?  The tournament field is sdfall3, thanks!

<?php
$RandyFind = $fm->newFindCommand('mylayout');
$RandyFind->addFindCriterion('sdfall3', '1');
$RandyFind->addSortRule('ssvm', 1, FILEMAKER_SORT_DESCEND);

$RandyFind->setRange(0,500);
$result = $RandyFind->execute();

if (FileMaker::isError($result)) {
    echo($result->getMessage());
    return;
}

?>

The issue you are now addressing; is probably one the most stupid parts of Filemaker's implementation.

I already answered this issue in this thread: http://fmforums.com/topic/98272-can-i-perform-an-if-count-before-a-result-is-executed/

Found count of 0 is really a valid search result; yet FileMaker chooses to throw an error.

<?php
$q = $fm->newFindCommand( 'mylayout' );
$q->addFindCriterion(     'sdfall3',
                          '1' );
$q->addSortRule(          'ssvm',
                           1,
                           FILEMAKER_SORT_DESCEND );
$q->setRange( 0, 500 );
$r = $q->execute();

if( FileMaker::isError( $r ) && $r->code != 401 ) {
  echo( $r->getMessage() );
  return;
}
?>

 

Edited by ggt667

To be fair, FileMaker client throws an error for 0 found as well...

Any any application, knowing what the error states are and trapping nicely for them is important.

Cheers

Webko

Error 0 always means no error; in most other applications there could be notifications, warning, and other log objects regardless.

Like for command line tools return 0 = no error

I expressed that badly ggt...

Rephrased:

To be fair, FileMaker client throws an error (401) for a found set of zero records (no records found) as well...

FileMaker is the only application I have ever seen that replies with a return code exception for found count of 0

couchDB, mariaDB, MySQL, FoxPro, postgreSQL does not do that.

For dd to do such a thing there has to be failure in the media or controller.

 

To be fair the ability to check $r['foundCount'] == 0 alone should be enough, no need for the $r->code == 401

Edited by ggt667

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.