douyi0902 2014-03-18 22:12
浏览 32

用mysql打破分页

i am trying to get my pagination to work but im having a problem, the "switching between" pagen wont work at all, and the results is not really working to well. Can someone help to get it working cause i cant for my life get it to work and i have tried so much :/

<?

 if (!(isset($pagenum))) 

 { 

 $pagenum = 1; 

 } 

$currentpage = 20;
 $data_p = mysql_query("SELECT * FROM dogs LIMIT $currentpage") or die(mysql_error()); 


//This is where you display your query results

 while($info = mysql_fetch_array( $data_p )) 

 { 

  $id=$info['id'];
    echo '<a href="/index.php?dogs='. $id .'">
        <img src="/thumbs/'. $id .'.jpg" width="100" height="100"  alt="" />
    </a>';

 echo "<br>";

 } 

 echo "<p>";


 // This shows the user what page they are on, and the total number of pages

 echo " --Page $pagenum of $last-- <p>";


 // First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.

 if ($pagenum == 1) 

 {

 } 

 else 

 {

 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";

 echo " ";

 $previous = $pagenum-1;

 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";

 } 


 //just a spacer

 echo " ---- ";


 //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links

 if ($pagenum == $last) 

 {

 } 

 else {

 $next = $pagenum+1;

 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";

 echo " ";

 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";

 } 

 ?> 
  • 写回答

1条回答 默认 最新

  • duanbi6522 2014-03-18 22:17
    关注

    Unless you are working with register_globals=on, you need to get initial pagenum value with $_GET['pagenum'] instead of $pagenum

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?