473,327 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

pagination problem

40
can somebody please help me with this.im extracting values from the database and displaying them.but since the results are huge i've done pagination.the first page gets displayed fine.but when i click on the 2nd page,the page gets reloaded and no results are displayed.i cant figure out where im going wrong.please help

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once "../inc/functions.php";
  3. require_once "../inc/vars.inc.php";
  4. sessionCheck();
  5. session_start();
  6.  
  7. $old_sessionid = session_id(); //i've added these lines
  8.  
  9. session_regenerate_id(); //i've added these lines
  10.  
  11. $new_sessionid = session_id(); //i've added these lines
  12.  
  13. function cleanInput($input) {
  14.     $search = array(
  15.         '@<\s*script[^>]*?>.*?<\s*/\s*script\s*>@si',            // Strip out javascript
  16.         '@<\s*[\/\!]*?[^<>]*?>@si',                                                // Strip out HTML tags
  17.         '@<\s*style[^>]*?>.*?<\s*/\s*style\s*>@siU',            // Strip style tags properly
  18.         '@<![\s\S]*?–[ \t\n\r]*>@',
  19.                  '/<img[^>]+\>/i'                                                // Strip multi-line comments
  20.     );
  21.     $output = preg_replace($search, '', $input);
  22.     return $output;
  23. }
  24.  
  25. // ’slashing
  26. function sanitize($input) {
  27.     if (is_array($input)) {
  28.         foreach($input as $var=>$val) {
  29.             $outputs[$var] = sanitize($val);
  30.         }
  31.     } else {
  32.         $input = @trim($input);
  33.         if (get_magic_quotes_gpc()) {
  34.             $input = stripslashes($input);
  35.         }
  36.         $input  = cleanInput($input);
  37.         $outputs = escape($input);
  38.     }
  39.     return $outputs;
  40. }
  41.  
  42. $_GET = sanitize($_GET);
  43.     ?>
  44.  
  45.     <?php include_once "admin_templates/case_header.php"; ?>
  46. <html>
  47.  
  48. <head>
  49. <title>Multiple drop down list box from plus2net</title>
  50.  <link type="text/css" rel="stylesheet" href="../inc/jscalender/css/jscal2.css" />
  51.   <link type="text/css" rel="stylesheet" href="../inc/jscalender/css/border-radius.css" />
  52.   <link id="skin-win2k" title="Win 2K" type="text/css" rel="alternate stylesheet" href="../inc/jscalender/css/win2k/win2k.css" />
  53.   <link id="skinhelper-compact" type="text/css" rel="alternate stylesheet" href="../inc/jscalender/css/reduce-spacing.css" />
  54.   <script src="../inc/jscalender/js/jscal2.js"></script>
  55.   <script src="../inc/jscalender/js/lang/en.js"></script>
  56.  
  57. <SCRIPT language=JavaScript>
  58. function reload(form)
  59. {
  60. var val=form.cat.options[form.cat.options.selectedIndex].value;
  61. self.location='test2.php?cat=' + val ;
  62. }
  63.  
  64. </script>
  65. </head>
  66.  
  67. <body>
  68.  
  69. <?
  70.  
  71. @$cat=$_GET['cat']; 
  72. if(strlen($cat) > 0 and !is_numeric($cat)){ 
  73. echo "Data Error";
  74. exit;
  75. }
  76.  
  77.  
  78.  
  79. $quer2=caseQuery("SELECT DISTINCT gazetted,cat_id FROM category order by gazetted"); 
  80.  
  81. if(isset($cat) and strlen($cat) > 0){
  82. $quer=caseQuery("SELECT DISTINCT type FROM subcategory where cat_id=$cat order by type"); 
  83. }else{$quer=caseQuery("SELECT DISTINCT type FROM subcategory order by type"); } 
  84.  
  85. ?>
  86.  
  87. <form action="test2.php" name="srch_frm" method="post">
  88. <fieldset style="width:20px">
  89. <legend ><b> Search File</b></legend>
  90.   <table width="328" border="1">
  91.   <tr width="320">
  92.   <td >gazetted</td>
  93.   <td>
  94.   <?php
  95. echo "<select name='cat' onchange=\"reload(this.form)\" ><option value=''>Select one</option>";
  96. while($noticia2 = mysql_fetch_array($quer2)) { 
  97. if($noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[gazetted]</option>"."<BR>";}
  98. else{echo  "<option value='$noticia2[cat_id]'>$noticia2[gazetted]</option>";}
  99. }
  100. echo "</select>";
  101. ?>
  102. </td>
  103. </tr>
  104.  
  105. <tr>
  106. <td>type</td>
  107.  
  108. <td>
  109. <?php
  110. echo "<select name='subcat' ><option value=''>Select one</option>";
  111. while($noticia = mysql_fetch_array($quer)) { 
  112. echo  "<option value='$noticia[type]'>$noticia[type]</option>";
  113. }
  114. echo "</select>";
  115.  
  116.  
  117. ?>
  118. </td>
  119. </tr>
  120.   <td>Keyword:</td>
  121.   <td><input name="key" id="key" type="text" size="15"  value="<?=$_POST['key']?>" /></td>
  122.   </tr>
  123.   <tr>
  124.       <td>Date:</td>
  125.   <td><input name="sdate" id="sdate" type="text" size="15" value="<?=( $_POST['sdate'] ? $_POST['sdate'] : "" )?>" readonly="readonly" />
  126.   <img src="http://bytes.com/submit/images/cal.gif" id="srcDOFImg">
  127.  
  128.             <script type="text/javascript">
  129.           new Calendar({
  130.                   inputField: "sdate",
  131.                   dateFormat: "%d-%m-%Y",
  132.                   trigger: "srcDOFImg",
  133.                   bottomBar: true,
  134.                   //max:  Calendar.dateToInt(new Date()),
  135.                   onSelect: function() {
  136.                           var date = Calendar.intToDate(this.selection.get());
  137.                           this.hide();
  138.                   }
  139.           });
  140.         </script>
  141.         </td>
  142.   </tr>
  143.   <tr>
  144.       <td>Name:</td>
  145.       <td>
  146. <input type="text" name="no" id="no" size="15"  value="<?=( $_POST['no'] ? $_POST['no'] : "" )?>"  />
  147.         <b>eg:0910-41</b></td>
  148.   </tr>
  149. </table>
  150.   <input name="Search" type="submit" value="Search" >
  151.   <input name="cancel" value="Cancel" type="reset" onClick="reload(this.form)">
  152.  </fieldset>
  153. </form>
  154. <?php
  155.  
  156. if($_POST['Search']){
  157. global $downloadPath;
  158.  
  159.     $gazetted = escape($_POST['cat']);
  160.     $type = escape($_POST['subcat']);    
  161.     $keyword = trim(escape($_POST['key']));
  162.     $sdate = escape($_POST['sdate']);
  163.     $no = trim(escape($_POST['no']));
  164. /*    
  165.     //Search filter function
  166.     $output = searchFilter($gazetted,$type,$keyword,$sdate,$no);
  167.  
  168.     }
  169.  
  170. function searchFilter($gazetted,$type,$keyword,$sdate,$no){
  171.  
  172.     */
  173.  
  174.     if($gazetted=='1' || $gazetted=='2'){
  175.  
  176.         $sqlWhere[]="pan_document_master.pan_doc_gazetted = '".$gazetted."'";
  177.     }
  178.  
  179.     if($type=='ORDERS' || $type=='NOTIFICATIONS' || $type=='ELECTIONS' || $type=='OTHERS'){
  180.         $sqlWhere[]="pan_document_master.pan_doc_type = '".$type."'";
  181.     }
  182.     if($keyword){
  183.         $sqlWhere[]="pan_document_sub_master.pan_doc_keyword = '".$keyword."'";
  184.     }
  185.     if($sdate){
  186.         $sqlWhere[]="pan_document_sub_master.pan_doc_date = '".$sdate."'";
  187.     }
  188.     if($no){
  189.         $sqlWhere[]="pan_document_sub_master.pan_doc_name = '".$no."'";
  190.     }
  191.  
  192.     if(!is_array($sqlWhere)){
  193.         $msg[] = "<h3>No Search Filter Specified</h3>";
  194.     }
  195.  
  196. if(!$msg){
  197. $page = $_GET['page'];
  198.     $records_per_page = 2;
  199.     if (!ctype_digit($page)) $page=1;
  200.     $offset = ($page-1) * $records_per_page;
  201.     $sqlWhere[]= "pan_document_master.pan_doc_gazetted=pan_document_sub_master.pan_document_type";
  202.  
  203.     $srcTerm = @implode(' AND ',$sqlWhere);
  204.  
  205.     $count = 1;
  206.         $sql = "select * from `pan_document_master`,`pan_document_sub_master` where ".$srcTerm." ORDER BY pan_document_master.gazetted LIMIT $offset, $records_per_page";
  207.  
  208.         $rows = caseQuery($sql);
  209. if (mysql_num_rows($rows)){
  210.  
  211.     $output =    '<table border="1" style="border:1px solid #000000; border-collapse:collapse;" width="100%">
  212.             <tr>
  213.                 <td width="2%" align="center"><strong>Sr.No.</strong></td>
  214.                 <td width="5%" align="center"><strong>Gazetted</strong></td>
  215.                 <td width="10%" align="center"><b>Type</b></td>
  216.                 <td width="14%" align="center"><b>Keyword</b></td>
  217.                 <td width="14%" align="center"><b>Date</b></td>
  218.                 <td width="15%" align="center"><b>Name</b></td>
  219.                 <td width="10%" align="center"><b>View</b></td>
  220.                 </tr>    ';
  221.  
  222.             while($result = @mysql_fetch_object($rows)){
  223.             $sql="select `pan_doc_path` from pan_document_sub_master where pan_doc_sub_id = '".$result->pan_doc_sub_id."'";
  224.             $rowspath = caseQuery($sql);
  225.             if(@mysql_num_rows($rowspath)){
  226.                     $path='';
  227.                     while($paths = @mysql_fetch_object($rowspath)){
  228.  
  229.             $path .= "<a href='../".$downloadPath."/".$result->pan_doc_path."'>Download</a>";
  230.             }
  231.             }
  232.  
  233.         $file = stripslashes($path);
  234.     if($result->pan_doc_gazetted=='2'){
  235.                 $output.= '<tr valign="top">
  236.                                 <td align="center">'.$count++.'</td>
  237.                                 <td align="center">NO</td>
  238.                                 <td align="center">'.$result->pan_doc_type.'</td>
  239.                                 <td align="center">'.$result->pan_doc_keyword.'</td>
  240.                                 <td align="center">'.$result->pan_doc_date.'</td>
  241.                                 <td align="center">'.$result->pan_doc_name.'</td>
  242.                                 <td align="center">'.$file.'</td>';
  243.                                 }
  244.                                 else
  245.                             if($result->pan_doc_gazetted=='1'){
  246.                 $output.= '<tr valign="top">
  247.                                 <td align="center">'.$count++.'</td>
  248.                                 <td align="center">YES</td>
  249.                                 <td align="center">'.$result->pan_doc_type.'</td>
  250.                                 <td align="center">'.$result->pan_doc_keyword.'</td>
  251.                                 <td align="center">'.$result->pan_doc_date.'</td>
  252.                                 <td align="center">'.$result->pan_doc_name.'</td>
  253.                                 <td align="center">'.$file.'</td>';
  254.                                 }    
  255.                         }    
  256.  
  257.  
  258.  
  259.             $output .= '</table>';
  260.             //paging toolbar
  261.             //if($page<1) echo "<font size=3><b>Error Displaying Page</b></font>";
  262.             //else 
  263.             //{
  264.                     $count_result = caseQuery("SELECT COUNT(*) FROM  `pan_document_master`,`pan_document_sub_master` where ".$srcTerm."");
  265.                     $count_row = mysql_fetch_array($count_result);
  266.                     $count = $count_row["COUNT(*)"];        //fetch the total number of rows in the table
  267.                     $numofpages = ceil($count/$records_per_page);    // how many pages we have when using paging?
  268.                     if ($numofpages > '1' ) 
  269.                     {echo "$page";
  270.                     pagingScript("test2.php", $page, $numofpages);
  271.                      }else {
  272.                     echo "<p><b>No Gazette Details</b></p>";
  273.                 }
  274.                     //}
  275.                 //} else {
  276.                     //echo "<p><b>No Gazette Details</b></p>";
  277.                 //}
  278.  
  279.  
  280.         }else{
  281.             $output = "<h3>No files Found</h3>";
  282.         }
  283.     }else{
  284.          $output = addslashes(@implode("<br>",$msg));
  285.     }
  286.  
  287.     //return $output;
  288. }
  289.  
  290.  
  291. //echo "$output";
  292. //echo "$test";
  293. ?><? echo "$output"; ?>
  294. </body>
  295.  
  296. </html>
  297.  
  298.  

the pagination code is placed in a seperate file named functions.php.they are displayed below

Expand|Select|Wrap|Line Numbers
  1. function build_url($filename, $key, $value){
  2.   $values = array();
  3.   $query_str = array();
  4.   parse_str($_SERVER['QUERY_STRING'], $values);
  5.   foreach ($values as $k=>$v) {
  6.     if ($k!=$key) {
  7.       $query_str[] = "{$k}={$v}";
  8.     }
  9.   }
  10.   $query_str[] = "{$key}={$value}";
  11.   return "$filename?".implode("&amp;", $query_str);
  12. }
  13.  
  14. //paging script
  15. function pagingScript($filename, $page_num, $numofpages) {
  16.     $range = 20;
  17.     $range_min = ($range % 2 == 0) ? ($range / 2) - 1 : ($range - 1) / 2;
  18.     $range_max = ($range % 2 == 0) ? $range_min + 1 : $range_min;
  19.     $page_min = $page_num- $range_min;
  20.     $page_max = $page_num+ $range_max;
  21.  
  22.     $page_min = ($page_min < 1) ? 1 : $page_min;
  23.     $page_max = ($page_max < ($page_min + $range - 1)) ? $page_min + $range - 1 : $page_max;
  24.     if ($page_max > $numofpages) {
  25.         $page_min = ($page_min > 1) ? $numofpages - $range + 1 : 1;
  26.         $page_max = $numofpages;
  27.     }
  28.  
  29.     $page_min = ($page_min < 1) ? 1 : $page_min;
  30.  
  31.     $page_pagination .= "<br /><table align='center' width='100%'><tr><td align='left' width='10%'>";
  32.     if ( ($page_num > ($range - $range_min)) && ($numofpages > $range) ) {
  33.         $page_pagination .= '<a title="First" href="'.build_url($filename, "page", 1).'">&lt;&lt;</a> ';
  34.     }
  35.     if ($page_num != 1) {
  36.         $page_pagination .= '<a href="'.build_url($filename, "page", $page_num-1).'">Previous</a> ';
  37.     }
  38.     $page_pagination .= "</td><td align='center' width='80%'>";
  39.  
  40.     for ($i = $page_min;$i <= $page_max;$i++) {
  41.         if ($i == $page_num)
  42.             $page_pagination .= '<b>' . $i . '</b> &nbsp; ';
  43.         else
  44.             $page_pagination.= '<a href="'.build_url($filename, "page", $i).'">'.$i.'</a> &nbsp; ';
  45.     }
  46.  
  47.     $page_pagination .= "</td><td  align='right' width='10%'>";
  48.     if ($page_num < $numofpages) {
  49.         $page_pagination.= ' <a href="'.build_url($filename, "page", $page_num+1).'">Next</a>';
  50.     }
  51.     if (($page_num< ($numofpages - $range_max)) && ($numofpages > $range)) {
  52.         $page_pagination .= ' <a title="Last" href="'.build_url($filename, "page", $numofpages).'">&gt;&gt;</a> ';
  53.     }
  54.     $page_pagination .= "</td></tr></table><br />";
  55.  
  56.     echo $page_pagination;
  57. }
  58.  
  59.  
  60.  
Feb 15 '10 #1
2 1763
whitep8
65
i had a similar problem and the solution ended up being in my face

pagination is easy to get the first selection, as you have proven. When you click the "next 20" it should include a GET value being posted back to itself for the next sets starting point.

for for first 10 it would just include your search string, but when you click next an additional parameter would go into the url to say where it should start from again
Feb 16 '10 #2
lisles
40
ya thanx alot.i realised that and already did it.thanx ayways
Feb 17 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kurzman | last post by:
Let me know what you think about the following code: DECLARE @MaxIdValue int DECLARE @MaxSortFieldValue nvarchar(50) SELECT TOP 1 @MaxIdValue = , @MaxSortFieldValue = FROM ( SELECT TOP...
2
by: Chris H | last post by:
I am having a problem with pagination, basically the problem is happening in the "PREV / NUMBERS / NEXT" links, it appears as if the reason is becasue the increment and decrement operators aren't...
11
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. ...
0
by: Sheau Wei | last post by:
I am using php version 4.3.3. The below was my pagination code. My problem is that when i run this code in my computer, i wall fail because of the hyperlink of the pagination not function when i...
2
by: s4lin | last post by:
problem is pagination not retaining data field i have form with general data field, and i need to select some option which is store in database, so i open another page with retrieving data from...
1
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that...
16
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) ...
1
markrawlingson
by: markrawlingson | last post by:
Hello, For starters: Yes, I am new to asp.net, however I hold a good 9-10 years of experience working with classic asp and am only just now upgrading my skills. I'm picking asp.net up pretty...
4
by: ArizonaJohn | last post by:
Hello, The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed. I am trying to use pagination with it,...
2
by: kkshansid | last post by:
this is my search page on which i am getting two parameters from previous page but the problem is that as soon as i click any other next pages my sql query fails as it doesnt get these two parameters...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.