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

1

How do I select all the records in a page? Similar to what gmail does where ever, by checking the checkbox that only selects that of the current page, a text appears just above to select all other records that are separated into multiple pagination pages. This in PHP.

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

    
asked by anonymous 13.02.2014 / 02:04

3 answers

1

I would do it as follows:

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

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

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

(3) Perform your operation.

What the 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 4th executes the action on all the result of the saved query in the first step.

Good luck!

    
06.03.2014 / 18:16
0

At first all that is needed is a boolean variable. 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 value of the variable by sending / receiving its value between client and server.

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

In server-side you check: If todos_registros is true then you perform the operation on all registers.

    
13.02.2014 / 02:14
0

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

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

Notice that each checkbox is named a reference to the messages array. So when you submit this form, this will be the result array you will have on server side:

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

I hope it solves what you have in mind - personally, I find the solution more phatic.

    
13.02.2014 / 12:08