Jump to content

Pagination Option


mcmuney

Recommended Posts

Below (A) is a portion of my pagination code where I specify the limit. What I'd like to do is add a select function (B) that will allow users to specify the limit. On change of select option, it should refresh with the new limit:

 

A

	//-------------------start paging-------------------------

	$page = $_GET['page'];  
	$limit = 25;
	$total=count($rest_avg_score);

	// work out the pager values 
	$pager  = Pager::getPagerData($total, $limit, $page);  
	$offset = $pager->offset;  
	$limit  = $pager->limit;  
	$page   = $pager->page; 

	$sql.= " limit $offset, $limit";

//-------------------end paging-------------------------

 

B

<select name="intMaxResults">
<option value="10">10</option>
<option value="25" selected>25</option>
<option value="50">50</option>
<option value="75">75</option>

<option value="100">100</option>
<option value="125">125</option>
<option value="150">150</option>
<option value="175">175</option>
<option value="200">200</option>
</select>

Link to comment
https://forums.phpfreaks.com/topic/40949-pagination-option/
Share on other sites

<?php

	$page = $_GET['page'];  

                if ($_POST['intMaxResults']){
                   $limit = $_POST['intMaxResults'];
                } else {
                   $limit = 25; //Whatever you want the default to be
                }

	$total=count($rest_avg_score);

	// work out the pager values 
	$pager  = Pager::getPagerData($total, $limit, $page);  
	$offset = $pager->offset;  
	$limit  = $pager->limit;  
	$page   = $pager->page; 

	$sql.= " limit $offset, $limit";

?>

Link to comment
https://forums.phpfreaks.com/topic/40949-pagination-option/#findComment-198308
Share on other sites

Try this. This will allow the user to submit the form, and it will automatically update the limit.

 

<?php

     if ($_POST['submit']){

	$page = $_GET['page'];  

                if ($_POST['intMaxResults']){
                   $limit = $_POST['intMaxResults'];
                } else {
                   $limit = 25; //Whatever you want the default to be
                }

	$total=count($rest_avg_score);

	// work out the pager values 
	$pager  = Pager::getPagerData($total, $limit, $page);  
	$offset = $pager->offset;  
	$limit  = $pager->limit;  
	$page   = $pager->page; 

	$sql.= " limit $offset, $limit";
     }

print<<<HERE
<p>
<form action = "{$_SERVER['PHP_SELF']}" method="POST">

<select name="intMaxResults">
<option value="10">10</option>
<option value="25" selected>25</option>
<option value="50">50</option>
<option value="75">75</option>

<option value="100">100</option>
<option value="125">125</option>
<option value="150">150</option>
<option value="175">175</option>
<option value="200">200</option>
</select>
<p>
<input type="submit" name="submit" value="Update!">

</form>

HERE;

?>


Link to comment
https://forums.phpfreaks.com/topic/40949-pagination-option/#findComment-198323
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.