i have this script which searches a db then return the results, i really urgently need this to work! it limits the results to 10 per page. What happens is, i search, it returns the navigation with the correct number of pages, it creates a table with the right columsn etc on the first page, but when i click onto page 2 or any other there are no results, then i click back to page one and all the results disappear :S. Thanx in advance
<?php
// Database Connection
include 'db.php';
$search = $_POST['search'];
// 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 = 10;
// 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
$sql = mysql_query("SELECT * FROM archive WHERE name = '$search' AND approved = '1' LIMIT $from, $max_results");
echo "<table width=90% align=center border=1 bordercolor=#111111 style=border-collapse: collapse><tr>
<font face='Tahoma'>
<td align=center bgcolor=#FFFFFF><font face='Tahoma'>ID</td>
<td align=center bgcolor=#FFFFFF><font face='Tahoma'>File Name</td>
<td align=center bgcolor=#FFFFFF><font face='Tahoma'>Author</td>
</tr></font>";
while($row = mysql_fetch_array($sql)){
// Build your formatted results here.
$name = $row['name'];
$author = $row['author'];
$ref = $row['ref'];
$authorurl = $row['authorurl'];
$printname = "<a href=file.php?id=$ref>$name</a>";
$printauthor = "<a href=$authorurl>$author</a>";
echo "<tr>
<td align=center>$ref</td>
<td align=center>$printname</td>
<td align=center>$printauthor</td>";
}
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM archive"),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>";
?>