Pagination prob

My problem is with my pagination system it works but it wont show the numbers correctly.
I have 8 items in the DB and have it set to show 5 and i should get this: 1 2 next on the first page, but i get this:1 next. And once you get to the 2nd page it keeps going even though there is no data.


<!--- content --->
   <img src="images/trans.gif" width="1" height="10" alt="" border="0"><br>
   <table width="763" cellpadding="0" cellspacing="0" border="0">
	<tr>
	 <td width="763" align="left" valign="top">
	  <table cellpadding="0" cellspacing="0" border="0">
	   <tr>
	   <?
	   include ("connect.php");
	   $category = $_GET['category'];
	   
	   /// pagination ///
	   if(!isset($_GET['page'])){ 
	   $page = 1; 
	   } else { 
	   $page = $_GET['page']; 
	   } 
	   
	   // Define the number of results per page 
	   $max_results = 5; 
	   
	   // 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 
	   $result = mysql_query("SELECT * FROM products WHERE category='$category' LIMIT $from, $max_results");
	   
	   $total_results = mysql_num_rows($result); 
	   $total_pages = ceil($total_results / $max_results);
	   /// end pagination ///
	   
	   $count = 1;
		  while($r=mysql_fetch_array($result)){
		 $title=$r["title"];
		  $image=$r["image"];
		  $price=$r["price"];
		  $code=$r["code"];
		  $sizes=$r["sizes"];
		  $category=$r["category"];
		  $id=$r["id"];
		 
	   ?>
			  <td valign="top" align="left">
				  <table width="92" cellpadding="0" cellspacing="0" border="0">
		  <tr>
		   <td colspan="4" valign="top" align="left">
			<img src="images/thumb_top.jpg" width="87" height="5" alt="" border="0"><br>
		   </td>
		  </tr>
		  <tr>
		   <td width="5" valign="top" align="left">
			<img src="images/thumb_left.jpg" width="5" height="86" alt="" border="0"><br>
		   </td>
		   <td width="77" valign="top" align="left">
			<a href="detail.php?id=<?=$id?>" target="details"><img src="images/products/thumbs/<?=$image?>" width="77" height="86" alt="<?=$title?>" border="0"></a><br>
		   </td>
		   <td width="5" valign="top" align="left">
			<img src="images/thumb_right.jpg" width="5" height="86" alt="" border="0"><br>
		   </td>
		   <td width="5" valign="top" align="left">
			<img src="images/trans.gif" width="5" height="5" alt="" border="0"><br>
		   </td>
		  </tr>
		  <tr>
		   <td colspan="4" valign="top" align="left">
			<img src="images/thumb_bottom.jpg" width="87" height="5" alt="" border="0"><br>
		   </td>
		  </tr>
		  <tr>
		   <td colspan="4" valign="top" align="center">
			<span class="title">
			<?=$title?><br>
			</span>
			<img src="images/trans.gif" width="1" height="5" alt="" border="0"><br>
		   </td>
		  </tr>
		 </table>
			  </td>
				<?php
				if ($count == 5) {
				  echo "</tr>
<tr>
";
		  $count = 0;	
				}
		  $count++;
	  }
				?>
		  </tr>
	  </table>
	  <span class="linkbut">
	  <?
	  //prev link
	  if($page != 1){
		  //echo '<a href="copy2.php?page=1&category='.$category.'">First</a> ';
		  echo '<a href="copy2.php?page=' . ($page - 1) . '&category='.$category.'">&laquo; Previous</a> ';
	  }
	  // number 123 links
	  for($i = 1; $i <= $total_pages; $i++){
		  if($i != $page){
			  echo '<a href="copy2.php?page=' . $i . '&category='.$category.'">' . $i . '</a> ';
		  }else{
			  echo $i . ' ';
		  }
	  }
	  //next link
	  if($page != $max_results){
	  //if($i != $max_results - 1){
		  echo '<a href="copy2.php?page=' . ($page + 1) . '&category='.$category.'">Next &raquo;</a> ';
		  
	  }?>
	  </span>
	 </td>
	 <td width="284">
	  <iframe name="details" src="detail-filler.php" width="284" height="365" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
	  <img src="images/trans.gif" width="1" height="10" alt="" border="0"><br>
	 </td>
	</tr>
   </table>
   
   <!--- /content --->