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.
Am I somehow losing the content of my array or not reading it again?
[php] <?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);
// Get required page number. If not present, default to 1.
if (isset($_GET['pageno']))
{$pageno = $_GET['pageno'];
}
else
{$pageno = 1;
}
// 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;
//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 the LIMIT clause for the sql SELECT statement
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$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";
}
$result = mysql_query($query) or die ("Could not execute the query"); //executes the query
//Count the number of results
$data_rows=mysql_num_rows($result);
echo "<p class='style7'>Your search: "".$fnamesearch." ".$lnamesearch."" returned <b>".$data_rows."</b> results.</p>";
//Calculate number of pages based on results per page
if ($data_rows == 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>";
}
echo "</table>";
}
//construct the hyperlinks which will allow the user to select previous pages
if ($pageno == 1)
{echo " FIRST PREV ";
}
else
{echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
}
//inform the user of his current position in the sequence of available pages
echo " ( Page $pageno of $lastpage ) ";
//provide the links for any following pages
if ($pageno == $lastpage)
{echo " NEXT LAST ";
}
else
{$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
}
mysql_free_result($result); //release the result set from the table
mysql_close($conn); //close the connection to the db
?>[/php]