October 12, 201510 yr 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;?>
October 12, 201510 yr 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 October 14, 201510 yr by ggt667
October 13, 201510 yr Author Thanks ggt667, I'm gonna try some kind of workaround, I appreciate your efforts!
October 15, 201510 yr 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;} ?>
October 15, 201510 yr 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 October 15, 201510 yr by ggt667
October 15, 201510 yr 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
October 16, 201510 yr 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
October 16, 201510 yr 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...
October 16, 201510 yr 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 October 16, 201510 yr by ggt667
Create an account or sign in to comment