Hello all,
I am writing a function to do one of the things that is going to be used a number of times through out the site, and it works except when i don't put one of the argurments into the function, I do have a default value set for it. so the question is what am I doing wrong? Another problem with this is that if I put a / in the url so it would show up as yoursite.com/?sq ... it keeps adding another / when hitting any of the four links (please note right now I don't have the / in the code.
Any help will be grateful!
<?php
$sq = "test"; // var from url
$tr = 172; // total rows found from the search
$pn = $_GET['pn']; // page number that is being displayed
// $rpp = 20; // tells how many results to show on one page
function page_bar($sq, $tr, $rpp = '20', $pn)
{
$fp = 1; // first page
$lp = ceil($tr/$rpp); // last page
$page_nav_bar = ''; // var thats used to hold what will be displayed for the page nav bar
if($pn > $fp)
{
$page_nav_bar .= "<a href=\"http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] ."?sq=$sq&pn=$fp\">First</a> ";
$page_nav_bar .= ' | ';
$pp = $pn - 1;
$page_nav_bar .= "<a href=\"http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] ."?sq=$sq&pn=$pp\">Prev</a> ";
}
$page_nav_bar .= " Page $pn of $lp ";
if($pn < $lp)
{
$np = $pn + 1;
$page_nav_bar .= "<a href=\"http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] ."?sq=$sq&pn=$np\">Next</a>";
$page_nav_bar .= ' | ';
$page_nav_bar .= "<a href=\"http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] ."?sq=$sq&pn=$lp\">Last</a>";
}
return "$page_nav_bar";
}
echo "<center>" . page_bar($sq, $tr,$pn) . "</center>";
?>
Sincerely,
Christopher