Jump to content
Server Maintenance This Week. ×

Script Only Returning Last Result


SChaput

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

Recommended Posts

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

Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...
  • 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>';
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This topic is 3963 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.