dongxie2613 2011-10-10 13:15
浏览 42

如果没有其他条目显示,如何删除分页脚本中的“下一个”选项?

I have this script that I have posted a bunch of times but was never able to explain clearly how it was working. But now I can, so here it is. I am trying to show the option to see "next" only when there are more entries to be shown.

  $result =   mysql_query("SELECT * FROM table WHERE field1 LIKE '%$q%' 
  OR field2 LIKE '%$q%' OR field3 LIKE '%$q%' OR field4 LIKE '%$q%'");


  $num_rows1 = mysql_num_rows($result);

//check if the starting row variable was passed in the URL or not
if (!isset($_GET['pg']) or !is_numeric($_GET['pg'])) {
  //we give the value of the starting row to 0 because nothing was found in URL
  $startrow = 0;
  //otherwise we take the value from the URL
} else {
  $startrow = (int)mysql_real_escape_string($_GET['pg']);
}

$sql = "SELECT field1, field2, field3, field4 FROM table WHERE
user_id='$id' limit $startrow, 10";
$result = mysql_query($sql);

$query = mysql_query($sql) or die ("Error: ".mysql_error());

if ($result == "") {
  echo "";
}

echo "";

$rows = mysql_num_rows($result);

if($rows == 0) {
  print("");
} elseif($rows > 0) {
  while($row = mysql_fetch_array($query)) {
    $field1 = $row['field1'];
    $field2 = $row['field2'];
    $field3 = $row['field3'];
    $field4 = $row['field4'];

    print("");
  }
}

if($num_rows1 > 10) {
  echo '<a id=pg href="'.$_SERVER['PHP_SELF'].'?pg='.($startrow+10).'&q='.($q).'"> Next</a>';
} 

$prev = $startrow - 10;

//only print a "Previous" link if a "Next" was clicked
if ($prev >= 0) {
  echo '<a id=pgnvg2 href="'.$_SERVER['PHP_SELF'].'?pg='.$prev.'&q='.($q).'">
  Previous</a>';
}
  • 写回答

1条回答 默认 最新

  • doufeixuan8882 2011-10-10 13:25
    关注

    Pagination:

     Total Items
     Items per Page
     Current Page
    

    You only need to show the next navigation if:

     Total Items >= Items per Page * (Current Page + 1)
    

    That simple it is.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b