How to select separate records on multiple pages of a PHP pagination?

Asked

Viewed 485 times

1

How to select all records of a pagination? Similar to what gmail does where it always does , when marking checkbox which selects only the one of the current page, a text appears just above to select all the other records that are separated into several pages of the pagination. This in PHP.

Example in gmail even after a search, the page shows 100 results, but it is possible to select tb all records only referring to that search that are in the other pages of the pagination.

  • 3

    Very broad question. Show the code of how you are currently making your pagination so we can have a basis. Edit your question and add some code.

3 answers

1

I’d do it this way:

(1) Place a checkbox in a highlighted location on the page (indicating that it is a multiple selection);

(2) Make the click on the checkbox enable a javascript where:

(a) all visible page checkbox elements are selected (to give the full selection effect); (b) carry out a selection of all elements of the criterion (whether or not they are listed on the page). In my applications, I like to show next to the selector the total number of selected items, this gives an additional confirmation to the user that he has selected all items and not just those on the page.

(3) Carry out your operation.

What GMAIL does is identical to the above. When performing a filter it does the following procedure 1º executes the query and saves the result, 2º shows a number x of results, 3º when selecting all it marks the x results on the screen (for presentation purposes only) and 4º executes the action over the entire query output saved in the 1st step.

Good luck!

  • thanks buddy, that’s just what I need, you would have some example of 4th Code ??

0

At first, all that is needed is a variable boolean. Example:

// no client-side (javascript)
var todos_registros = false;   // valor inicial

// no server-side (php)
todos_registros = boolval($_REQUEST['todos_registros']);   // recebendo via Ajax

Use Ajax to synchronize the variable value, sending/receiving its value between client and server.

So what do you do with this variable? No client-side, just mark all the checkboxes or equivalent as checked. Or update the interface in some other way that the user knows you’ve selected everything. (In short: take care of UX.)

In the server-side you check: if todos_registros for true then you perform the operation on all records.

0

Suppose you have, in client-side, a series of records, each associated with a checkbox:

<ul>
    <li><input type="checkbox" name="messages[]" value="message1">Mensagem 1</li>
    <li><input type="checkbox" name="messages[]" value="message2">Mensagem 2</li>
    <li><input type="checkbox" name="messages[]" value="message3">Mensagem 3</li>
</ul>

Note that each checkbox is named after an array reference messages. So, when you submit this form, this will be the array of results you get on the server side:

Array
(
    [messages] => Array
        (
            [0] => message1
            [1] => message2
            [2] => message3
        )
)

I hope you solve what you have in mind - personally, I find the most poetic solution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.