Ok, here is the code to what I have already, if there is 500 results and there is 20 results on a page it would have 50 links from 1 to 50 on the bar along with first page, pre and next, last page.
also this code is not changing the results like it should. I have passed through a $_GET var sq= ... which also needs to be on all them links
Thanks very much for your help with this!
Sincerely,
Christopher
Code:
include '/home/dev/www/search/search_form.php';
$search_query = $_GET['sq'];
$perpage = 20; if(isset($_GET["perpage"])) { $perpage =$_GET["perpage"];}
$pagenum = 1; if(isset($_GET["page"])) { $pagenum =$_GET["page"];}
include '/home/dev/www/search/lib/db_config_ro-dev.php';
include '/home/dev/www/search/lib/db_conn-select.php';
$offset = ($pagenum - 1) * $perpage;
$field1 = "PNO";
$field2 = "SN_SNL";
$query = " SELECT * FROM query WHERE $field1 LIKE '%$search_query%' OR $field2 LIKE '%$search_query%' LIMIT $offset, $perpage";
$result = mysql_query($query) OR die("Was unable to get the results!" . mysql_error());
$rows = mysql_num_rows($result) OR die("Was unable to get number of rows" . mysql_error());
$num = mysql_affected_rows();
// how many rows we have in database
$query = " SELECT * FROM query WHERE $field1 LIKE '%$search_query%' OR $field2 LIKE '%$search_query%'";
$result = mysql_query($query) OR die("Was unable to get the results!" . mysql_error());
$numrows = mysql_num_rows($result) OR die("Was unable to get number of rows" . mysql_error());
// $num = mysql_affected_rows();
// how many pages we have when using paging?
$maxPage = ceil($numrows/$perpage);
// print the link to access each page
$self = $_SERVER['HTTP_REFERER'];
$page_num_nav = "";
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pagenum)
{
$page_num_nav .= " $page "; // no need to create a link to current page
}
else
{
$page_num_nav .= " <a href=\"$self?page=$page&sq=$search_query\">$page</a> ";
}
}
if ($pagenum > 1)
{
$page = $pagenum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ""; // we're on page one, don't print previous link
$first = ""; // nor the first page link
}
if ($pagenum < $maxPage)
{
$page = $pagenum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ""; // we're on the last page, don't print next link
$last = ""; // nor the last page link
}
$result_bar = $first . $prev . $page_num_nav . $next . $last;