Jump to content

Results pagination problem - changing results per page value


Catfish

Recommended Posts

I am making a php script that will browse the contents of a mysql table and have pagination of the results. The scripts accepts a value for "results per page". I want this value to be user definable through the interface so I figured a text input box would suffice.

 

I have run into a problem and not sure the best way to fix it. The browse script does a few things. It shows a pageful of results and creates page navigation links and the "result per page" input box, but I also want it to allow the user to select any number of records and then perform actions on them (edit, delete, export etc.) So my form is built something like:

 

<html>
<form>
<input type="checkbox" name="data[]" value="$recordIDNum" />
<!-- etc. over and over for all records displayed and $recordIDNum varies -->
<input type="submit" name="a" value="Edit" /><input type="submit" name="a" value="Delete" /> <!-- etc. for all actions that can be done -->
<input type="text" name="resultsPerPage" value="$_SESSION['resultsPerPage']" />
</form>
</html>

 

Now... how my scripts work is based off the value of the 'a' variable. It will include() a php file for each action I create. So when I enter a value for results per page and press enter, it is using the submit button "Edit" so sets 'a' to "Edit" and then wants to include the php file for "Edit" which is wrong. I want it to leave 'a' as "Browse Table" and reload the browse page, with the new result per page value.

 

Any hints?

Link to comment
Share on other sites

Worked this one out eventually.

 

Have to include a hidden <input> value for 'a' whose value is "Browse Table" (the action name I want when user changes results per page value).

The <input> tag for the result per page value has to have an attribute called "onchange" with value "submit();"

 

so:

<form method="get" action="scriptname.php">
  <input type="hidden" name="a" value="Browse Table" />
  <input type="text" name="resultsPerPage" value="5" onchange="submit();" /> <!-- default value in box is 5 -->
  <input type="submit" name="a" value="Edit" /> <!-- etc. for other submit action values -->
</form>

 

When user changes the value of resultsPerPage, the page will reload using the hidden value of 'a' (Browse Table) instead of the first submit type input value (Edit). Without the onchange="submit();" attribute, the script uses the Edit action instead of the hidden value.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.