I am in need of a little bit of help. I have a PHP MYSQL search program in place that I just finally figured out how to return a limited number of results with the option of going to however many pages of results there are for each query. My problem is that I can only view the results from the first page. I can go to the "next" page, but it doesn't return anymore of the actual records, just the table heading. Any suggestions would be greatly appreciated.
Here is my search script,
PHP:
<html>
<body>
<h1><center>Audit Database Search</center></h1>
<br><br><br><br>
<form method="post" action="http://mysql/phppages/pppppp.php" target="_blank">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td bordercolor="#000000">
<p align="center">
<select name="metode" size="1">
<option value="DT_STRING">Date</option>
<option value="ACCOUNT">Account</option>
<option value="ACCOUNT_TYPE">Account Type</option>
<option value="CLIENT_ID">Client ID</option>
<option value="USER_ID">User ID</option>
</select> <input type="text" name="search" size="25"> <br>
</td>
</tr>
</table>
</div>
<br>
<form method="post" action="http://mysql/phppages/pppppp.php" target="_blank">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td bordercolor="#000000"><div>
<p align="center">
<select name="metode2" size="1">
<option value="DT_STRING">Date</option>
<option value="ACCOUNT">Account</option>
<option value="ACCOUNT_TYPE">Account Type</option>
<option value="CLIENT_ID">Client ID</option>
<option value="USER_ID">User ID</option>
</select> <input type="text" name="search2" size="25"> <br>
Search database: <input type="submit" value="Go!!" name="Go"></p>
</form>
</body>
</html>
and here is the results page that I am having the troubles with
PHP:
<center>
<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">
<tr>
<td width="60"><b>DT_STRING</b></td>
<td width="100"><b>ACCOUNT</b></td>
<td width="30"><b>ACCOUNT_TYPE</b></td>
<td width="150"><b>CLIENT_ID</b></td>
<td width="150"><b>USER_ID</b></td>
</tr>
<tr>
<td>
<?php
mysql_connect(mysql, root, rootroot) or die("ERROR--CAN'T CONNECT TO SERVER");
mysql_select_db("AUDITMED") or die("ERROR--CAN'T CONNECT TO DB");
if(!isset($GET['page'])){
$page = 1;
} else {
$page = $GET['page'];
}
$max_results = 30;
$from = (($page * $max_results) - $max_results);
$metode = $REQUEST['metode'];
$search = $REQUEST['search'];
$metode2 = $REQUEST['metode2'];
$search2 = $REQUEST['search2'];
$sql = mysql_query("SELECT * FROM AUDIT WHERE $metode LIKE '%$search%' AND $metode2 LIKE '%$search2%' LIMIT $from, $max_results");
if(mysql_num_rows($sql) >= 1)
{
while ($row = mysql_fetch_array($sql)){
{
$variable1=$row["DT_STRING"];
$variable2=$row["ACCOUNT"];
$variable3=$row["ACCOUNT_TYPE"];
$variable4=$row["CLIENT_ID"];
$variable5=$row["USER_ID"];
//table layout for results
echo ("<tr>");
echo ("<td>$variable1</td>");
echo ("<td>$variable2</td>");
echo ("<td>$variable3</td>");
echo ("<td>$variable4</td>");
echo ("<td>$variable5</td>");
echo ("</tr>");
}
}
}
else
{
"Your search criterea returned no results";
}
$total_results = mysql_result(mysql_query("SELECT COUNT(*) FROM AUDIT WHERE $metode LIKE '%$search%' AND $metode2 LIKE '%$search2%'"),0);
$total_pages = ceil($total_results / $max_results);
echo "<center>Select a Page<br />";
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
}
}
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";
?>
</table>
</center>
Thanks again!