September 29, 201114 yr Newbies Good day all, I am in the middle of trying to create this script so I can view our filemaker pro databases on the web. However, it seems to only be returning the last found record. I use $result = $cmd->execute(); $records = $result->getRecords(); which shows me the script finds 3 results, however all the content is outputted as if it were the last record. Find the entire code set below: <?php ini_set('error_reporting', 1); //config removed $return_field =array("ID", "Primary"); # set the layout name for this page $layout_name = 'Asset'; # this is the include for the API for PHP require_once ('Filemaker.php'); # instantiate a new FileMaker object $fm = new FileMaker(FM_FILE, FM_HOST, FM_USER, FM_PASS); $field = $_GET['field']; $search = $_GET['search']; $cmd = $fm->newFindCommand($layout_name); $cmd->addFindCriterion($field, $search); $result = $cmd->execute(); if( FileMaker::isError($result) ) { echo $result->getMessage() ; die(); } $records = $result->getRecords(); echo 'Total Records Found: ' . count($records); echo "<br><br>"; foreach($records as $record){ foreach($return_field as $field){ echo $field . ': ' . $record->getField($field) . '<br>'; } echo "<br>--------------<br>"; } Thanks for the help!
September 29, 201114 yr $return_field is undefined. Actually, you don't need or want that foreach(return_field) loop at all. foreach($records as $record){ echo $field . ': ' . $record->getField($field) . '<br>'; echo "<br>--------------<br>"; }
September 29, 201114 yr Author Newbies Thanks for the response, however, even removing that section of code still only returns the final result, but still sees that there are three total records found. <?php ini_set('error_reporting', 1); //config removed # set the layout name for this page $layout_name = 'asset'; # this is the include for the API for PHP require_once ('Filemaker.php'); # instantiate a new FileMaker object $fm = new FileMaker(FM_FILE, FM_HOST, FM_USER, FM_PASS); $field = $_GET['field']; $search = $_GET['search']; $cmd = $fm->newFindCommand($layout_name); $cmd->addFindCriterion($field, $search); $result = $cmd->execute(); if( FileMaker::isError($result) ) { echo $result->getMessage() ; die(); } $records = $result->getRecords(); echo 'Total Records Found: ' . count($records); echo "<br><br>"; foreach($records as $record){ echo $record->getField('ID') . '<br>'; echo "<br>--------------<br>"; }
June 26, 201312 yr Newbies *BUMP* Did you solved this problem? Having the exact same issue with my php-site when i try to search thru the records in my database.
June 26, 201312 yr Newbies Here it is! require_once ('FileMaker.php'); $fm = new FileMaker(); $fm->setProperty('database', 'xxxxx'); $fm->setProperty('hostspec', 'xxxxx'); $fm->setProperty('username', 'xxxxx'); $fm->setProperty('password', 'xxxxx'); $find =& $fm->newFindCommand('www'); $find->addFindCriterion('Namn', "ståhl"); $result = $find->execute(); $records = $result->getRecords(); //var_dump($records); echo '<table>'; foreach ($records as $record) { echo '<tr><td>'. $record->getField('Namn'). '</td><td>'. $record->getField('Befattning/Yrke'). '</td></tr>'; } echo '</table>';
June 26, 201312 yr I could duplicate your result (first record only returned) if I used FileMaker 11 PHP API files (FileMaker.php and the FileMaker folder). Switching to FileMaker 12 PHP API files corrected the problem. See http://help.filemaker.com/app/answers/detail/a_id/6531/~/manually-installing-the-filemaker-api-for-php
Create an account or sign in to comment