Jump to content

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


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

Recommended Posts

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 );

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

$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
Link to comment
Share on other sites

2 hours ago, jamescv7 said:

I saw this link http://www.databuzz.com.au/simple-pagination-with-the-filemaker-php-api/ but still figuring out on how to show it properly.

Is this really the examples out there?

When we wrote FX.php at least we made sure it had complete examples.

Edited by ggt667
Link to comment
Share on other sites

@ggt667:  The information of examples in API of Filemaker are limited (only in official PDF).

 

Unfortunately I have no money to purchase paid ebooks since it contains the information I wanted to look.

http://stackoverflow.com/questions/2427115/filemaker-php-next-previous-buttons-on-record-detail-page

I found also this but its too limited and barely understand the syntax.

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

  • 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

Link to comment
Share on other sites

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