有序列表没有在PHP中正确显示数字序列?

时间:2014-01-16 14:30:27

标签: php

有序列表在第一页上显示正常,但在下一页上,它还显示上一页的最后一个数字。如何解决这个问题?

这是我的完整代码:

<?php
  $sql01 = "SELECT COUNT(*) FROM pm";
  $result = mysql_query($sql01, $conn) or trigger_error("SQL", E_USER_ERROR);
  $r = mysql_fetch_row($result);
  $numrows = $r[0];
  $rowsperpage = 3;

  // find out total pages
  $totalpages = ceil($numrows / $rowsperpage);

  // get the current page or set a default

  if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
     // cast var as int
     $currentpage = (int) $_GET['currentpage'];
  } 
  else 
  {
     // default page num
     $currentpage = 1;
  } // end if

  // if current page is greater than total pages...  
  if ($currentpage > $totalpages) {    
     // set current page to last page
     $currentpage = $totalpages;
  } // end if

  // if current page is less than first page...   
  if ($currentpage < 1) {
     // set current page to first page
     $currentpage = 1;
  } // end if

  // the offset of the list, based on current page 
  $offset = ($currentpage - 1) * $rowsperpage;

  // get the info from the db 
  // while there are rows to be fetched...
  $sql=mysql_query("select *from pm where send_to='$_GET[name]' limit $offset, $rowsperpage");
  $sql2=mysql_query("select *from pm_reply where send_to='$_GET[name]' limit $offset, $rowsperpage");
  $start_from = $offset + 1;
  echo "<ol start='$start_from'>";
  while($rows=mysql_fetch_assoc($sql)){
     echo"<li>From: <a href='profile.php?name=$rows[send_by]'>$rows[send_by]</a><br><br><a style='text-decoration:none; font-size:14pt;' href='view_pm.php?name=$_GET[name]&pm=$rows[subject]'>$rows[subject]</a></li>"; 
     echo "<hr>";
     echo "<br>";
  }

  while($rows2=mysql_fetch_assoc($sql2)) {
     echo"<li>From: <a href='profile.php?name=$rows2[replied_by]'>$rows2[replied_by]</a><br><br><a style='text-decoration:none; font-size:14pt;' href='view_pm.php?name=$_GET[name]&pm=$rows2[subject]'>$rows2[subject]</a></li>"; 
     echo "<hr>";
     echo "<br>"
  }

  echo "</ol>";
  echo "</div>";
  //End Div Content

0 个答案:

没有答案