this is the code for search button
if ($go == 'Go')
{
if ($searchText == '')
{
$buttonPress = 2;
echo "<script>alert('Please complete the information!')</script>";
}
else if ($searchText != '')
{
$result2 = mysql_query("SELECT * FROM sec_ph WHERE phType LIKE '%$searchText%' OR phCustomer LIKE '%$searchText%' ") or die(mysql_error());
$resultRow2 = mysql_num_rows($result2);
if ($resultRow2 == '0')
{
$buttonPress = 2;
echo "<script>alert('No Matches Found!')</script>";
}
else if ($resultRow2 != '0')
{
$buttonPress = 1;
echo "<center><form action = 'http://10.237.102.158/Problem_History/' method = 'post'>";
echo "Search: <input type = 'text' name = 'searchText' size = 30> ";
echo "<input type = 'submit' name = 'go' value = 'Go'></form></center>";
$result3 = mysql_query("SELECT * FROM sec_ph WHERE phType LIKE '%$searchText%' OR phCustomer LIKE '%$searchText%' ORDER BY phStatus")
or die(mysql_error());
echo "<center>";
$pagenumSearch = $_GET["pagenumSearch"];
//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenumSearch)))
{
$pagenumSearch = 1;
}
$rows = mysql_num_rows($result3); //Here we count the number of results
$page_rows = 5; //This is the number of results displayed per page
$last = ceil($rows/$page_rows); //This tells us the page number of our last page
if ($pagenumSearch < 1) //this makes sure the page number isn't below one, or more than our maximum pages
{
$pagenumSearch = 1;
}
elseif ($pagenumSearch > $last)
{
$pagenumSearch = $last;
}
//**********************************************TOTAL RECORD COUNT
$resultCount = mysql_query("SELECT COUNT(*) FROM sec_ph") or die(mysql_error());
$count = mysql_result($resultCount,0,0);
echo "<b></center>Total Record Count: </b> $count record(s)<br><br><center>";
//***********************************************SEARCH RESULTS
echo "<u><center><b>Search Results: " . $resultRow2 . " Match(es) Found</b><br><br></u>";
$max = 'LIMIT ' .($pagenumSearch - 1) * $page_rows .',' .$page_rows; //This sets the range to display in our query
$result4= mysql_query("SELECT * FROM sec_ph WHERE phType LIKE '%$searchText%' OR phCustomer LIKE '%$searchText%' ORDER BY phStatus $max")
or die(mysql_error());
echo "<table border = 1 bordercolor='#996633' cellpadding = 4><tr bgcolor = #FFFFCC><th><font size = 2>Type</th><th><font size = 2>Customer</th></tr>";
while($row = mysql_fetch_array($result4))
{
echo "<tr><td><font size = 2>";
echo $row['phType'];
echo "</td><td><font size = 2>";
echo $row['phCustomer'];
echo "</td></tr>";
}
echo "</table>";
echo "<br><br><center>Page<b> $pagenumSearch </b>of<b> $last</b><br><br>"; // This shows the user what page they are on, and the total number of pages
// First we check if we are on page one.
//If we are then we don't need a link to the previous page or the first page so we do nothing.
//If we aren't then we generate links to the first page, and to the previous page.
if ($pagenumSearch == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenumSearch=1'>First</a> ";
echo " ";
$previous = $pagenumSearch-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenumSearch=$previous'>Previous</a> ";
echo " ";
}
//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenumSearch == $last)
{
}
else
{
$next = $pagenumSearch+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenumSearch=$next'>Next</a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenumSearch=$last'>Last</a> ";
}
echo "</font></center>";
}
}
}
this is the code for the index page viewing the database contents
switch ($buttonPress)
{
case 1: " ";
break;
case 2: echo "<center><form action = 'http://10.237.102.158/Problem_History/' method = 'post'>";
echo "Search: <input type = 'text' name = 'searchText' size = 30> ";
echo "<input type = 'submit' name = 'go' value = 'Go'></form></center>";
$result = mysql_query("SELECT * FROM sec_ph ORDER BY phStatus") or die(mysql_error());
echo "<center>";
$pagenum = $_GET["pagenum"];
//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}
$rows = mysql_num_rows($result); //Here we count the number of results
$page_rows = 5; //This is the number of results displayed per page
$last = ceil($rows/$page_rows); //This tells us the page number of our last page
if ($pagenum < 1) //this makes sure the page number isn't below one, or more than our maximum pages
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
$resultCount = mysql_query("SELECT COUNT(*) FROM sec_ph") or die(mysql_error());
$count = mysql_result($resultCount,0,0);
echo "<b></center>Total Record Count: </b> $count record(s)<br><br><center>";
$max = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This sets the range to display in our query
$result2 = mysql_query("SELECT * FROM sec_ph ORDER BY phStatus $max") or die(mysql_error());
echo "<table border = 1 bordercolor='#996633' cellpadding = 4><tr bgcolor = #FFFFCC><th><font size = 2>Type</th><th><font size = 2>Customer</th></tr>";
while($row = mysql_fetch_array($result2))
{
echo "<tr><td><font size = 2>";
echo $row['phType'];
echo "</td><td><font size = 2>";
echo $row['phCustomer'];
echo "</td></tr>";
}
echo "</table>";
echo "<br><br><center>Page<b> $pagenum </b>of<b> $last</b><br><br>"; // This shows the user what page they are on, and the total number of pages
// First we check if we are on page one.
//If we are then we don't need a link to the previous page or the first page so we do nothing.
//If we aren't then we generate links to the first page, and to the previous page.
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>Previous</a> ";
echo " ";
}
//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last)
{
}
else
{
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next</a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
}
echo "</font></center>";
break;
default: break;
}
of course, at the start of the code, $buttonPress = 2, to enable it.
*****now, the problem is that, whenever i access the next/first/last/previous links when i click the go button of the search engine, it goes back to the default page, i mean it runs the $buttonPress =2;, now, what i did was that, i change the variable $pagenum to $pagenumSearch, for some sort of distinction, however, it does not work, what should i do?????
please, really need bad help!
tnx...