<?php$offset = isset($_GET['pid'])?intval($_GET['pid']):1;if(!$offset) $offset = 1;$perpage = 50;$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 $perpage OFFSET ".($offset-1);$result = $db->query($sql);if ($result){ foreach ($result->fetchAll() as $row) { echo "subject: ".$row[5]."<br />"; }}else{ $error = $db->errorInfo(); echo "error happened..".$error[2]; exit();}buildIndex($perpage, $total);//1,50,3500/////////////////////////////////////////////////////////////////function buildLink($index, $offset){ echo "<a href ='". htmlentities($_SERVER['PHP_SELF'])."?pid = $offset'>$index</a>";}function buildIndex($perpage, $total){ $separator = '|'; //buildLink($offset==1, '<<Prev', '') for ($start = 1, $end = $perpage; $end < $total; $start += $perpage, $end += $perpage) { echo $separator; buildLink("$start-$end", $start); } $end = ($total > $start) ? "$total":""; echo $separator; buildLink("$start-$end", $start);}?>
<?php$offset = isset($_GET['pid'])?intval($_GET['pid']):1;if(!$offset) $offset = 1;$perpage = 50;$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 -1)*$perpage.", $perpage ";$result = $db->query($sql);if ($result){ foreach ($result->fetchAll() as $row) { echo "subject: ".$row[5]."<br />"; }}else{ $error = $db->errorInfo(); echo "error happened..".$error[2]; exit();}$numpage = $total%$perpage;if($total%$perpage) $numpage++;$cur = $offset;if ($cur < $numpage){ echo "<a href ='". htmlentities($_SERVER['PHP_SELF'])."?offset = ".($cur+1)."'> Next Page</a><br />";}if($cur > 0){ echo "<a href ='". htmlentities($_SERVER['PHP_SELF'])."?offset =". ($cur-1)."'> Prev Page</a><br />";}?>
受信オフセットを処理しているのを見ませんでした
受信オフセットを処理しているのを見ませんでした
ここで上記を参照してください次のように変更します。
$offset = isset($_GET['pid'])?intval($_GET['pid']):1;if(!$offset) $offset = 1;开头就处理了啊
42 行目には ...setPage02.php? offset=$i'>$i....
2 行目は $offset = isset($_GET[' intval($ _GET)] です['オフセット']) : 1;
何が問題かわかりますか?
42 行目は ...setPage02.php? offset=$i'>$i....
2 行目は $offset = isset($_GET[' intval($_GET']) ? 'オフセット']) : 1;
何が問題かわかりますか?
。 42 行目は ...setPage02.php? offset=$i'>$i....
2 行目は $offset = isset($_GET['offset']) ? ]): 1;
何が問題か知っていますか?