pagination for PHP - MySQL - next pages dont show results

Hi,

my page is currently up at brewhas.org/transactions.php. When I retrieve a set of results > the defined # per page (such as entering ‘WI’ for last name), I see the first page correctly, and see the links to next pages, but when I go to the next page there are no results displayed. Same for p.3, etc.

So I’ve looked around enough to know that I need to pass a variable to the subsequent pages, either via a session variable or the URL. I have 2 fields input on the form, as well as a limit and offset. My questions are 1) do I need to pass all 4 and if so then should I use a session variable so the URL does not get too long, and 2) can anyone provide any help with setting session variables and including them to be passed?

I’m a newbie and have grabbed some code online but this is where i’m stuck. thanks in advance.

		<?php
				include 'config.php';
				include 'opendb.php';
				$rows_per_page = 20;

					//Get the values from the text boxes			
					$fnamesearch = $_POST["fnamesearch"];
					$lnamesearch = $_POST["lnamesearch"];

					//These trim and convert the name fields to upper case.
					$fnamesearch=strtoupper($fnamesearch);
					$lnamesearch=strtoupper($lnamesearch);
					$fnamesearch=trim($fnamesearch);
					$lnamesearch=trim($lnamesearch);
			
					// Count how many rows are coming back for the query
					//This checks to see if there are at least 2 chars in the last name.
					if (strlen($lnamesearch)<2)
						{
							echo "<p class='style7'>Please enter at least 2 letters of the last name.</p>";
							exit;
						}
					else  //sets the query to get the number of rows
						{
							$query = "SELECT COUNT(*) FROM BKL_TRANSACTIONS WHERE((PLAYER_LNAME LIKE '$lnamesearch%')& (PLAYER_FNAME LIKE '$fnamesearch%'))";
						}

					$result = mysql_query($query) or die ("Could not execute the query");   //executes the get count query
					$query_data = mysql_fetch_row($result);
					$numrows = $query_data[0];
					echo "count: ".$numrows;	
					$lastpage = ceil($numrows/$rows_per_page);		//determines how many pages based on rows divided by rows per page
					echo "pages: ".$lastpage;

					// Get required page number.  If not present, default to 1.
					if (isset($_GET['pageno']) && is_numeric($_GET['pageno'])) 
						{$pageno = $_GET['pageno'];
						} 
					else 
						{$pageno = 1;
						} 
					
					//Checks that the value of $pageno is an integer between 1 and $lastpage.
					$pageno = (int)$pageno;
					if ($pageno > $lastpage) 
						{$pageno = $lastpage;
						} 
					if ($pageno < 1) 
						{$pageno = 1;
						}						
				
					//constructs OFFSET for the sql SELECT statement
					$offset = ($pageno - 1) * $rows_per_page;
					
					//This checks to see if there are at least 2 chars in the last name.
					if (strlen($lnamesearch)<2)
						{
							echo "<p class='style7'>Please enter at least 2 letters of the last name.</p>";
							exit;
						}
					else  //sets the query to get the number of rows
						{
							$query = "SELECT * FROM BKL_TRANSACTIONS WHERE((PLAYER_LNAME LIKE '$lnamesearch%')& (PLAYER_FNAME LIKE '$fnamesearch%')) LIMIT $offset, $rows_per_page";
						}
	
					$result = mysql_query($query) or die ("Could not execute the query");   //executes the query
					//Count the number of results 
					$numrows=mysql_num_rows($result);
					
					echo "<p class='style7'>Your search: &quot;".$fnamesearch." ".$lnamesearch."&quot; returned <b>".$numrows."</b> results.</p>";
					
					if ($numrows == 0)  //if no matches, don't display the table 
							exit;
					else				//build the table and insert rows 
						{
									echo "<table border=1 cellspacing=0 cellpadding=1 width='77%' align=left bordercolor=#666666>";
									echo "<tr bgcolor=#cccc99 class='style5'><th width='10%' class='style5'>Date</th>";
									echo "<th width='10%' class='style5'>Action</th>";
									echo "<th width='12%' class='style5'>From</th>";
									echo "<th width='12%' class='style5'>To</th>";
									echo "<th width='5%' class='style5'>Pos</th>";
									echo "<th width='18%' class='style5'>Name</th>";		
									echo "<th width='5%' class='style5'>Round</th></tr>";							
	
								while ($row = mysql_fetch_array($result))
								{
									echo "<tr><td width='10%' class='style6'>".$row['TRANS_DT']."</td>";
									echo "<td width='10%' class='style6'>".$row['TRANS_ACTION']."</td>";
									echo "<td width='12%' class='style6'>".$row['FROM_OWNER']."</td>";
									echo "<td  width='12%' class='style6'>".$row['TO_OWNER']."</td>";
									echo "<td  width='5%' class='style6'>".$row['POSITION']."</td>";
									echo "<td  width='18%' class='style6'>".$row['PLAYER_FNAME']." ".$row['PLAYER_LNAME']."</td>";
									echo "<td  width='5%' class='style6'>".$row['DRAFT_RND']."</td></tr>";
								}
				
								/******  build the pagination links ******/	
								// if not on page 1, don't show back links
								if ($pageno > 1) {
								   // show << link to go back to page 1
								   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'><<</a> ";
								   // get previous page num
								   $prevpage = $pageno - 1;
								   // show < link to go back to 1 page
								   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'><</a> ";
								}
								// range of num links to show
								$range = 3;

								// loop to show links to range of pages around current page
								for ($x = ($pageno - $range); $x < (($pageno + $range)  + 1); $x++) {
								   // if it's a valid page number...
								   if (($x > 0) && ($x <= $lastpage)) {
									  // if we're on current page...
									  if ($x == $pageno) {
										 // 'highlight' it but don't make a link
										 echo " [<b>$x</b>] ";
									  // if not current page...
									  } else {
										 // make it a link
										 echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$x'>$x</a> ";
									  } // end else
								   } // end if 
								}
								// if not on last page, show forward and last page links        
							if ($pageno != $lastpage) {
							   // get next page
							   $nextpage = $pageno + 1;
								// echo forward link for next page 
							   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>></a> ";
							   // echo forward link for lastpage
							   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>>></a> ";
							} // end if
							/******  end build pagination links ******/					
							echo "</table>";
						}		
					mysql_free_result($result);	 //release the result set from the table
					mysql_close($conn);			 //close the connection to the db
				?>
Sponsor our Newsletter | Privacy Policy | Terms of Service