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.

PHP Pagination Show Record individually by first, previous, next and last

Featured Replies

You will most likely write your code in a way that your user can tell the browser something like this: http://www.domain.tld/scriptname?skip=10&show=20

$show = $_REQUEST['show'];
$skip = $_REQUEST['skip'];
if( ! isset( $skip ) ) {
  $skip = 0;
}
if( ! isset( $show ) ) {
  $show = 20;
}

$request->setRange( $skip, $show );

 

  • Author

Then how I will show the records one at a time with the use of Session? I'm still new to Filemaker PHP API. 

None I can see a proper procedure except the pagination showing by batch.

Edited by jamescv7

$show = 1;
$skip = $_REQUEST['skip'];
if( ! isset( $skip ) ) {
  $skip = 0;
}

$request->setRange( $skip, $show );

Oh, then you would make show=1 like as above

Edited by ggt667

  • Author

I've tried this link but nowhere I got the process right cause nothing happens.

 

 

  • Author
<?php
require_once 'FileMaker.php';


$fm = new FileMaker('Contacts_Carlo', 'armontsys.ddns.net', 'Admin', 'fenix101');


$layouts = $fm->listLayouts();
if(FileMaker::isError($layouts)) {
// FileMaker PHP API Error — Alert User.
$errorMessage = "FileMaker PHP Error: " . $layouts->getMessage();
} else {

// Find all Contact records
$request = $fm->newFindAllCommand('FPAM_testpurposeonly');

// Set a Max value. Paging 20 records at a time
$max = 1;

$skip = (isset($_GET['skip']));
if(!isset($skip)) { $skip = 0; }
$request->setRange($skip, $max);

// Perform the Find
$result = $request->execute();

if (FileMaker::isError($result)) {
if ($result->code = 401) {
$errorMessage = "There are no Contacts that match that request: "  . ' (' . $result->code . ')';
} else {
$errorMessage = "Contacts Find Error: " . $result->getMessage() . ' (' . $result->code . ')';
}

} else {

// Get the found records and setup page navigation links
$records = $result->getRecords();
$found = $result->getFoundSetCount();
$fetchcount = $result->getFetchCount();

// $totalpages = ceil($found / $max);

$prev = $skip - $max;
$next = $skip + $max;
if(($skip + $max) > $found) {$next = $skip; }

$lastskip = $found - ($found % $max);

$firstrecord = $skip + 1;

if ($fetchcount == $max) {
$lastrecord = (($firstrecord + $fetchcount) - 1);
} else {
$lastrecord = ($skip + $fetchcount);
}

$sepbar = " | ";

// Get the found records and setup page navigation links
$records = $result->getRecords();
$found = $result->getFoundSetCount();
$fetchcount = $result->getFetchCount();

$totalpagesceil = ceil($found / $max);
$totalpagesfloor = floor($found / $max);

$prev = $skip - $max;
$next = $skip + $max;
if(($skip + $max) > $found) {$next = $skip; }

if($totalpagesceil == $totalpagesfloor) {
$lastskip = ($totalpagesceil - 1) * $max;
} else {
$lastskip = $totalpagesfloor * $max;
}

$firstrecord = $skip + 1;

if ($fetchcount == $max) {
$lastrecord = (($firstrecord + $fetchcount) - 1);
} else {
$lastrecord = ($skip + $fetchcount);
}

$sepbar = " | ";

}
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>
FileMaker DevCon INT002 Contacts
</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/glass_grey.css">
<style type="text/css">
form#auth label.error { display: none;
margin-top: 5px;
color: red;}
.appropriateError{
color: red;
}
.emphasise{
color: red;
}
</style>
</head>
<body>
<div id="container">
<!-- HEADER -->
<div id="header">
<h1>
FileMaker DevCon INT002 Contacts
</h1>
</div></div>
<table>
<thead>
<tr>
<th>
Customer ID                          </th>
<th>
First Name                            </th>
<th>
Last Name                            </th>
<th>
Country                            </th>
<th>
Phone Mobile                          </th>
</tr>
</thead>
<tbody>
<?php
$records = $result->getRecords();
$recnum = 1;
foreach($records as $contacts_search_row){
$rowclass = ($recnum % 2 == 0) ? "table_row" : "alt_row";
$recid = $contacts_search_row->getRecordId();
$pos = strpos($recid, "RID_!");
if ($pos !== false) {
$recid = substr($recid,0,5) . urlencode(substr($recid,strlen("RID_!")));
}
?>
<tr>
<td><a href='<?php echo "contactdetails.php?recid=$recid";?>'><?php echo nl2br( $contacts_search_row->getField('Company'))?></a></td>
<td>
<?php echo nl2br( $contacts_search_row->getField('Address'))?>                            </td>
<td>
<?php echo nl2br( $contacts_search_row->getField('Phones'))?>                            </td>
<td>
<?php echo nl2br( $contacts_search_row->getField('Fax'))?>                            </td>
<td>
<?php echo nl2br( $contacts_search_row->getField('Factored'))?>                            </td>
</tr>
<?php $recnum++; } /* foreach record */?>
</tbody>
</table>
</div>
</div>
</body>
</html>


<div>

</div>
<div id=”content”>
<h1>Contacts List                </h1>

<div>

<?php
if ($skip != 0) {
echo '<a href="?skip=0">First</a>'.$sepbar;
}
?>

<?php
if ($prev >= 0) {
echo '<a href="?skip='.$prev.'">Previous</a>'.$sepbar;
}
?>



<?php
if (($skip + $max) < $found) {
echo '<a href="?skip='.$next.'">Next</a>'.$sepbar;
}
?>

<?php
if (($skip + $fetchcount) < $found) {
echo '<a href="?skip='.$lastskip.'">Last</a>';
}
?>

Fatal error: Call to undefined method FileMaker_Error::getRecords() in C:\xampp\htdocs\Attempt Pagination\paginationattempt.php on line 136

The code shows the data already but when I click next or Last then it turns out an undefined method. Pointing near end Tbody tag

Did you consider FX.php?

  • It's for free
  • It uses 20-30% less resources compared to phpFileMaker API( architectural benefit )
  • It actually has good examples.

That said there are benefits to using a better MVC / MVVM these days such as f ex Angular or the combination of Angular and FX.php is also a good fit.

Edited by ggt667

Also your code will benefit from keeping hierarchy; I do recommend 2 spaces pr tab. The error may or may not be open brackets.

I put indented copy here: http://termbin.com/b8zn

Edited by ggt667

  • Author

I will try to check FX.php

So on the code I posted, the error links only to open or close brackets?

 

The error seems pointing when I click next or last which failed to show data on for each loop. (except when it's in the main page)

  • Author

Is FX.php will work on Filemaker 15 version? According to the documentation, the API works from 7 to 14.

  • Author

I'm little bit confuse on FX and attempt to fix the source code that I posted.

However I don't know how to work it correctly. 

 

 

Can you post the whole source code on how the pagination works? This should help other users who are developing apps in PHP using the API itself.

  • Author

Never mind I fixed it already. 

Sometimes you need to purchase an ebook that contains the vital  important parts of Filemaker API functions.

20 hours ago, jamescv7 said:

Never mind I fixed it already. 

So are you saying that if somebody searches this forum and have the same issue as you; you are not going to give them the answer?

  • Author

Of course I'm willing to provide the solution, it seems I took a lot of time to just figure out the simple one.

So fortunately managed to purchase an ebook that contains the source code, however not sure if it's allowed to post here,

  • 2 weeks later...
On 5/9/2017 at 2:12 AM, jamescv7 said:

Is FX.php will work on Filemaker 15 version? According to the documentation, the API works from 7 to 14.

FX.php works from 5 to 16

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.