The pagination shows the the first 3 results, and makes link to the next 3 results, but when clicking next,  it doesn’t show a link to the next page if I want to see the last results. I’ve got a total of 8 results. the first page shows the first 3 results, when clicking next it show the next 3 results, but then there is no next link to see the last results. Anybody knows why it doesn’t work?
This is the full code
[php]
<?php   session_start();?>
<?php 
/*------------------------------------------------------------------------ 
            control codes 
------------------------------------------------------------------------*/ 
if ( (isset($_POST['submit'])) or (isset($_GET['pg'])) ) {   search();       //call the search function }else{ 
  show_form();   //call the show form function 
}//end if 
/*------------------------------------------------------------------------ 
            show the search form 
------------------------------------------------------------------------*/ 
function show_form() 
{ 
  //call the dropdown function which creates an html string to build a select box for each element 
  $be  = dropdown('be','behan'); 
  $omraede  = dropdown('omraede','behan'); 
  $pro     = dropdown('pro','behan'); 
 
  
  
  
  echo " 
        
 
        
        
 
          | 
 | 
 
         
          | Behandler: | >Alle
Fy
Ki | 
 
         
          | Område: | Alle
F
Sj
Jy | 
 
         
          | Pro: | Alle
yg
rm
F | 
 
  
        
        
        
         
           |  
          |  | 
 
        
        
  |  | 
        
 
        "; 
}//end function 
/*------------------------------------------------------------------------ 
            run the search and show the results 
------------------------------------------------------------------------*/ 
function search() 
{ 
if (isset($_POST)) {  foreach($_POST as $k=>$v) {    $_SESSION[$k]=$v;  }}
//Pagination 
  mysql_connect("localhost", "***", "****") or die(mysql_error());
mysql_select_db("*****") or die(mysql_error());
$getcount = mysql_query ("SELECT * FROM behan");
$postnum = mysql_result($getcount,0);
$limit = 3;
if($postnum > $limit)
{
$tagend = round($postnum % $limit,0);
$splits = round(($postnum - $tagend)/$limit,0);
if($tagend == 0)
{
$num_pages = $splits;
}
else
{
$num_pages = $splits + 1;
}
if(isset($_GET['pg']))
{
$pg = $_GET['pg'];
}
else
{
$pg = 1;
}
$startpos = ($pg*$limit)-$limit;
$limstring = "LIMIT $startpos,$limit";
}
else
{
$limstring = "LIMIT 0,$limit";
} 
/////////////////////////////////////
$sql = "SELECT * FROM behan WHERE 1=1"; 
//get the values from the form //NOTE: You should do way more valdation on the values before you attempt to process anything   
 if ((!empty($_SESSION['be']))&&($_SESSION['be'] != 'alle'))  
  {     $sql .= " and be like '". mysql_real_escape_string($_SESSION['be'])."%' ";   }     
  if ((!empty($_SESSION['omraede']))&&($_SESSION['omraede'] != 'alle'))  
   {     $sql .= " and omraede like '". mysql_real_escape_string($_SESSION['omraede'])."%' ";   }    
    if ((!empty($_SESSION['pro']))&&($_SESSION['pro'] != 'alle'))  
        
 {     $sql .= " and pro = '". mysql_real_escape_string($_SESSION['pro'])."' ";   } 
  // ADD ORDER BY  
  $sql .= " GROUP BY na order by total_value DESC $limstring ";
  
print "
";
  //run query 
 $result = conn($sql);
  if (!$result){ die("No results due to database error.
".mysql_error());  }
  if (mysql_num_rows($result)==0 && ($result)!='alle')
  {
echo "No results!
";
  }
  
else{
echo "";
$first_run = "true";
 while ($rows= mysql_fetch_array($result))
{
echo "";   
if ($first_run == "true"){
echo "| ";   
  
$first_run = "false";
}
if($_SESSION['pro'] != 'alle'){   
echo "Results: ";  
if (($_SESSION['be'] == 'alle')&&($_SESSION['omraede'] == 'alle')&&($_SESSION['pro'] == 'alle')) { echo "alle" ; }
if ($_SESSION['be'] != 'alle') { echo $rows['be'] ; }  echo " ";
if ($_SESSION['omraede'] != 'alle') { echo  $rows['omraede'] ;} echo " ";
if ($_SESSION['pro'] != 'alle') { echo $rows['pro'];}
echo " | 
";
echo "| ";
echo "Be | ";
echo "Rating | ";
echo "Ko | 
";
echo "";
echo "| ";
echo "". $rows['be'] ."". $rows['na'] ."
 ". $rows['ad'] ."
 ". $rows['por'] .", ". $rows['y'] ."
 ". $rows['tl'] ."
 | ". rating_bar($rows['id'],'6','static')." ";
echo " Bed  | ";
echo "Larer | 
";
echo ""; 
 }  
else {
echo "";
echo "| ";
echo "Be | ";
echo "Rating | ";
echo "Ko | 
";
echo "";
echo "| ";
echo "". $rows['be'] ."". $rows['na'] ."
 ". $rows['ad'] ."
 ". $rows['por'] .", ". $rows['y'] ."
 ". $rows['tl'] ."
 | ";
echo "Bed  | ";
echo ""; 
  //////////////////////// Links for pagination
if($postnum > $limit)
{
echo "Pages:    ";
$n = $pg + 1;
$p = $pg - 1;
$thisroot = $_SERVER['PHP_SELF'];
;
if($pg > 1)
{
echo "<< prev  ";
}
for($i=1; $i<=$num_pages; $i++)
{
if($i!= $pg)
{
echo "$i  ";
}
else
{
echo "$i  ";
}
}
if($pg < $num_pages)
{
echo "next >>";
}
echo "  ";
} 
/////////////////
}//end function 
/*------------------------------------------------------------------------ 
            create the drop downs 
------------------------------------------------------------------------*/ 
function dropdown($field, $table) 
{  
  //initialize variables 
  $oHTML  = ''; 
  $result = ''; 
  
  //check to see if the field is passed correctly 
  if (($field == "")||($table == "")) 
  { 
    die("No column or table specified to create drop down from!"); 
  } 
  $sql = "select distinct($field) from $table"; 
  
  //call the db function and run the query 
  $result = conn($sql); 
  //if no results are found to create a drop down return a textbox 
  if ((!$result) ||(mysql_num_rows($result)==0)) 
  { 
    $oHTML .= ""; 
  }
  
  elseif (($result)&&(mysql_num_rows($result)>0)){ 
    
    //build the select box out of the results 
   $oHTML .= "\nAlle\n";
  
  
    while ($rows = mysql_fetch_array($result)) 
    { 
      $oHTML .= "".$rows[$field]."\n"; 
    } 
    $oHTML .= "\n"; 
  } 
  
  //send the value back to the calling code 
  return $oHTML; 
}//end function 
?>Larer | [/php]