dswfyq6201 2012-09-18 03:23
浏览 53
已采纳

链接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>   
  • 写回答

1条回答 默认 最新

  • doutui2883 2012-09-18 03:26
    关注

    $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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器