suggestion for PEAR::PAGER class (code included)

From: Date: Mon, 03 Apr 2006 13:54:10 +0000
Subject: suggestion for PEAR::PAGER class (code included)
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-23515@lists.php.net to get a copy of this message
I am using the Pager class to page through results of a data set as you can see by looking at so I have used it frequently. the pager class has a function called getPagePerSelectBox which allows you to change the size of the window of the results from the DB query which are visible. I have some improvements made externally to the Pager module which the maintainer may decide to incorporate into this already tight little package.... 1. add a onChange to the select box form element 2. change max value in the select box to not exceed the max number of elements in the form. note: i make my own form just for the select box -----------------1------------------------- it is helpful to include the following javascript code to send the select box form automatically when it is changed. <script type="text/javascript" language=JavaScript> function submit_setPerPage(f) { // another javascript function dead in the water, except for firefox var check = false; var new_entrant = 0; var display_size = 0; var offset = <?=$offset?>; display_size = f.setPerPage.selected; f.setPerPage = f.setPerPage.selected; if (offset < display_size ) { new_entrant=1; } else { new_entrant = Math.floor(display_size / offset); } f.entrant= new_entrant; // alert('entrant='+new_entrant+' and display_size='+display_size); f.action = "index.php"; f.submit(); } however, that doesn't work in windows. i found in windows machine. // javascript broken on MSIE require_once('lib/browser.php');^M // File name: browser.php // Author: Gary White // Last modified: November 10, 2003 $br = new Browser;^M if ((strpos($br->Platform, "indow")>-1) || strpos($br->Name,"MSIE")>-1) { $selectBox .= "<input type=submit value='change'> &nbsp;"; } I then wrap the select in form tags. startForm('setPerPage',$bo_table,$wr_id, $entrant,0,'dict_pager','index.php') ; // startForm includes common variables in all my forms for me :) echo $selectBox; ?> &nbsp; </form> ------------- 2----------------------- get $max_from_db_table by issuing a count(*) query externally to the pager class, but there is a pager method numItems method for the Pager class which may do the same thing. $optionArr = array(5,10,15,20,25,30); foreach ($optionArr as $option) { if ($option == $items_per_page) { $max_option = $option; $selectBox .= "<option value='$option' selected='selected'>$option</option>"; } else { $max_option = $option; $selectBox .= "<option value='$option'>$option</option>"; } if ( $option >= $max_from_db_table ) break; /// it breaks when you send more than will fit /// it would have to start at a non-existing number } $selectBox .= "</select> &nbsp;"; // javascript broken on my MSIE win2k comptuer require_once('lib/browser.php');^M $br = new Browser;^M if ((strpos($br->Platform, "indow")>-1) || strpos($br->Name,"MSIE")>-1) { $selectBox .= "<input type=submit value='change'> &nbsp;"; } // function getPerPageSelectBox($start=5, $end=30, $step=5, $showAllData=false, $extraParams=array()) $selectBox = $selectBox_opening . $pager->getPerPageSelectBox(5, $max_option,5,true); }

« previous php.pear.general (#23515) next »