Jump to content

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


This topic is 3114 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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;?>

 

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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;
}

?>

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

This topic is 3114 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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