Jump to content


Photo

Viewing results after pagination is in place


  • Please log in to reply
No replies to this topic

#1 ccutla

ccutla
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 24 April 2006 - 03:49 PM

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"> &nbsp;<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"> &nbsp;<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

// Database Connection
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 current page number, use it
// if not, set one!

if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}

// Define the number of results per page
$max_results = 30;

// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);

// Perform MySQL query on only the current page number's 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");

//while($row = mysql_fetch_array($sql)){
// Build your formatted results here.
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";
}

// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) FROM AUDIT WHERE $metode LIKE '%$search%' AND $metode2 LIKE '%$search2%'"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

// Build Page Number Hyperlinks
echo "<center>Select a Page<br />";

// Build Previous Link
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> ";
}
}

// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";

?>
</table>
</center>


Thanks again!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users