时间:2021-07-01 10:21:17 帮助过:3人阅读
query('SELECT COUNT(*) FROM library.messages')->fetchColumn(0);$sql = 'SELECT * FROM library.messages'." LIMIT $perpage OFFSET ".($offset-1);$result = $db->query($sql);if ($result){ foreach ($result->fetchAll() as $row) { echo "subject: ".$row[5]."
"; }}else{ $error = $db->errorInfo(); echo "error happened..".$error[2]; exit();}buildIndex($perpage, $total);//1,50,3500/////////////////////////////////////////////////////////////////function buildLink($index, $offset){ echo "$index";}function buildIndex($perpage, $total){ $separator = '|'; //buildLink($offset==1, '<$start) ? "$total":""; echo $separator; buildLink("$start-$end", $start);}?>
query('SELECT COUNT(*) FROM library.messages')->fetchColumn(0);$sql = 'SELECT * FROM library.messages LIMIT '. ($offset -1)*$perpage.", $perpage ";$result = $db->query($sql);if ($result){ foreach ($result->fetchAll() as $row) { echo "subject: ".$row[5]."
"; }}else{ $error = $db->errorInfo(); echo "error happened..".$error[2]; exit();}$numpage = $total%$perpage;if($total%$perpage) $numpage++;$cur = $offset;if ($cur < $numpage){ echo " Next Page
";}if($cur > 0){ echo " Prev Page
";}?>
没有看到你处理传入的 offset
没有看到你处理传入的 offset
$offset = isset($_GET['pid'])?intval($_GET['pid']):1;if(!$offset) $offset = 1;开头就处理了啊
参考了下往上的,现在修改如下:
";//测试语句$perpage = 30; //每页显示30条目信息$offset = ($offset-1)*$perpage;$db = NEW PDO("mysql:host=localhost; port = 3306; dbname =library", 'root', 'cai123');$total = $db->query('SELECT COUNT(*) FROM library.messages')->fetchColumn(0); //获取信息的总数$sql = "SELECT * FROM library.messages LIMIT $offset, $perpage";$result = $db->query($sql);if ($result){ foreach ($result->fetchAll() as $row) { echo "subject: ".$row[5]."
"; }}else{ $error = $db->errorInfo(); echo "error happened..".$error[2]; exit();}$numpage = ceil($total/$perpage);if($total%$perpage) $numpage++;//计算可以显示为numpage页if ($numpage > 1){ for ($i = 1; $i <= $numpage; $i++) { if ($i == $offset) //如果是当前页 { echo "$i"; } else { //echo "$i "; echo "$i "; } }}
42 行有 ...setPage02.php? offset=$i'>$i....
而第 2 行是 $offset = isset($_GET[' ofset']) ? intval($_GET['offset']) : 1;
知道问题在哪了吧?
42 行有 ...setPage02.php? offset=$i'>$i....
而第 2 行是 $offset = isset($_GET[' ofset']) ? intval($_GET['offset']) : 1;
知道问题在哪了吧?
42 行有 ...setPage02.php? offset=$i'>$i....
而第 2 行是 $offset = isset($_GET[' ofset']) ? intval($_GET['offset']) : 1;
知道问题在哪了吧?