1

我正在尝试对我的结果进行分页,限制有效,页数设置正确,但是分页的链接不起作用,我已经找了一段时间了,没有,¿你能看看告诉我我做错了什么?谢谢

<?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>   
4

1 回答 1

1

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

应该

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

查询字符串以 a 开头,?但在第一个之后的任何名称-值对都需要一个 & 符号。

附带说明一下,您永远不应该将用户数据直接放入查询中。这使您容易受到 SQL 注入攻击。考虑使用mysql_real_escape_string或切换到mysqli 库

于 2012-09-18T03:26:22.193 回答