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 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果