mcmuney Posted March 3, 2007 Share Posted March 3, 2007 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 More sharing options...
pocobueno1388 Posted March 3, 2007 Share Posted March 3, 2007 <?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 More sharing options...
mcmuney Posted March 3, 2007 Author Share Posted March 3, 2007 Very helpful. Now, how do I get the form to refresh the page with the new limit onChange? Link to comment https://forums.phpfreaks.com/topic/40949-pagination-option/#findComment-198319 Share on other sites More sharing options...
pocobueno1388 Posted March 3, 2007 Share Posted March 3, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.