链接php mysql分页无法正常工作

i'm trying to paginate my results, the limit is working, the number of pages is properly set, but the links of the pagination don't work, i've been looking for a while and nothing, ¿can you take a look and tell me what i'm doing wrong? thanks

<?php
include("config/conexion.php");
$limit = 3;

if(isset($_GET['pag'])){
$pag= $_GET['pag'];
}else{
$pag=1;
}
$offset = ($pag-1) * $limit;


$sql = "SELECT SQL_CALC_FOUND_ROWS id, nombre, local, telefono, celular, email FROM almacenes WHERE id_cat = '".$_GET["id"]."'";
$sqlTotal = "SELECT FOUND_ROWS() as total";
$currentid = $_GET["id"];
$rs = mysql_query($sql);
$rsTotal = mysql_query($sqlTotal);

$rowTotal = mysql_fetch_assoc($rsTotal);
// Total de registros sin limit
$total = $rowTotal["total"];

?>
 <?php if($_GET["id"]){  $cat = mysql_query("SELECT * FROM almacenes WHERE id_cat = '".$_GET["id"]."' ORDER BY id ASC LIMIT $offset, $limit");  if(mysql_num_rows($cat)>0){

while($row = mysql_fetch_object($cat)){ ?>   

<div class="almacenbox">
    <div class="shadow"></div>
    <div class="white">
        <div class="image"><img src=almacenes/local_111.jpg></div>
        <div class="title"><?php echo $row->nombre?></div>
        <div class="text">Local: <?php echo $row->local?></div>
        <div class="text">Teléfono: <?php echo $row->telefono?></div>
        <div class="text">Celular: <?php echo $row->celular?></div>
        <div class="text"><?php echo $row->email?></div>
    </div>
    </div>
    <?php } ?>
    <?php } }else{ echo "<p>No hay resultados para mostrar</p>"; }?>
    <table border="1" bordercolor="#000">
  <tfoot>
  <tr>
     <td colspan="2">
  <?php
     $totalPag = ceil($total/$limit);
     $links = array();
     for( $i=1; $i<=$totalPag ; $i++)
     {
        $links[] = "<a href=almacenes.php?id=$currentid?pag=$i\>$i</a>"; 
     }
   echo implode(" - ", $links);
  ?>
     </td>
  </tr>
  </tfoot> </table>   

$links[] = "<a href=almacenes.php?id=$currentid?pag=$i\>$i</a>";

Should be

$links[] = '<a href="almacenes.php?id=$currentid&amp;pag=$i">$i</a>';

Query strings start with a ? but any name-value pairs after that first one require an ampersand.

On a side note you should never place user data directly into your query. This leaves you open to an SQL injection attack. Consider using mysql_real_escape_string or switching to the mysqli library.