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.

Script Only Returning Last Result

Featured Replies

  • 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!

$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>";

}

  • 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>";

}

  • 3 weeks later...

What does count($records) return?

  • 1 year later...
  • 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.

Post your php script.

  • 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>';

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.