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.

Search and Pagination on same page

Featured Replies

I'm running into a pagination problem while doing a search on the same page. I have a single search box which queries both the first name and last name of a person. The search works fine.

I also have pagination at the bottom of the page. I modified the pagination from here:

Pagination_1

Pagination_2

The pagination also works fine. When I enter a search criteria, I get the expected found set and a modified pagination (as expected). For instance, when I enter "ba" in the search box, 11 records are returned and pagination returns a "1" "2" and "Next" (I'm showing 10 records per page).

The problem occurs when I click on a pagination link (a number or "Next"); instead of going to the next records of the found set I get all the records returned.

It seems to me that this is happening because when I click a link I am reloading the page which executes a newFindCommand. I have tried to enter a condition in the script:

	if(array_key_exists($_POST["quicksearch"])) {

		echo "Array Key Exists!";

		exit();

		

	} else {

	

		$find = $fm->newFindCommand("web_individuals");

	

		$find->addFindCriterion("name_last", $search);

		$find->addFindCriterion("name_first", $search);

		$find->setLogicalOperator(FILEMAKER_FIND_OR);

		$find->addSortRule("name_last", 1);

		$find->addSortRule("name_first", 2);

	



		$per_page = 10;

		$start = $_GET['start'];

		$prev = $start - $per_page;

		$next = $start + $per_page;

	

		$find->setRange($start,$per_page);

		$result = $find->execute();

	

		$record_count = $result->getFoundSetCount();  



		$error = error_check($result);

	

		if(!$error) {

			$records = $result->getRecords();

		}

	}

but that didn't work.

To summarize, I am trying to do a quick search on the same page and have pagination to navigate through the found set.

In the event that it is not obvious, I am fairly new to PHP. Attached is the code in its entirety.

Thanks.

list_view.txt

  • Author

UPDATE:

I had to step away from this to think about it a little more. In the code originally posted I have a condition based on the array_key_exists() function. Really, what I want is to know if a pagination link was clicked, so I should be checking $_GET rather than $_POST.

I did some preliminary testing (a very simple condition at the top of the page) and that worked ok. What I can't seem to figure out is where to put the condition (i.e. the "if" statement) in the code that will keep the found set from the form (i.e. user generated query to filter the data).

I will keep working on it and post any insights if I have an "Aha" moment. I welcome any comments and/or instructions.

Thanks.

  • Author

UPDATE: Problem solved!

It occurred to me that I was using the $_POST variable when I should have used the $_GET variable. This put the search criteria in the URL (or URI - I'm not really that well read on the difference).

I have attached an updated version of the code. Anyone is welcome to use it as she/he likes.

Comments - especially on how the code might be improved - are very welcome.

This post turned out to be a conversation with myself and this was very helpful.

list_view_update.txt

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.