Rumah > Artikel > pembangunan bahagian belakang > 两个设置分页的都出有关问题,想屎了.
两个设置分页的都出问题,想屎了...
<br /><?php<br />$offset = isset($_GET['pid'])?intval($_GET['pid']):1;<br />if(!$offset) $offset = 1;<br />$perpage = 50;<br /><br /><br />$db = NEW PDO("mysql:host=localhost; port = 3306; dbname =library", 'root', 'cai123');<br />$total = $db->query('SELECT COUNT(*) FROM library.messages')->fetchColumn(0);<br /><br />$sql = 'SELECT * FROM library.messages'." LIMIT $perpage OFFSET ".($offset-1);<br />$result = $db->query($sql);<br />if ($result)<br />{<br /> foreach ($result->fetchAll() as $row)<br /> {<br /> echo "subject: ".$row[5]."<br />";<br /> }<br />}<br />else<br />{<br /> $error = $db->errorInfo();<br /> echo "error happened..".$error[2];<br /> exit();<br />}<br /><br />buildIndex($perpage, $total);//1,50,3500<br /><br />/////////////////////////////////////////////////////////////////<br />function buildLink($index, $offset)<br />{<br /> echo "<a href ='". htmlentities($_SERVER['PHP_SELF'])."?pid = $offset'>$index</a>";<br />}<br /><br /><br />function buildIndex($perpage, $total)<br />{<br /> $separator = '|';<br /> //buildLink($offset==1, '<<Prev', '')<br /><br /> for ($start = 1, $end = $perpage; $end < $total; $start += $perpage, $end += $perpage)<br /> {<br /> echo $separator;<br /> buildLink("$start-$end", $start);<br /> }<br /><br /> $end = ($total > $start) ? "$total":"";<br /> echo $separator;<br /> buildLink("$start-$end", $start);<br />}<br /><br /><br /><br /><br />?><br />
<br /><?php<br />$offset = isset($_GET['pid'])?intval($_GET['pid']):1;<br />if(!$offset) $offset = 1;<br />$perpage = 50;<br /><br /><br />$db = NEW PDO("mysql:host=localhost; port = 3306; dbname =library", 'root', 'cai123');<br />$total = $db->query('SELECT COUNT(*) FROM library.messages')->fetchColumn(0);<br /><br />$sql = 'SELECT * FROM library.messages LIMIT '. ($offset -1)*$perpage.", $perpage ";<br />$result = $db->query($sql);<br />if ($result)<br />{<br /> foreach ($result->fetchAll() as $row)<br /> {<br /> echo "subject: ".$row[5]."<br />";<br /> }<br />}<br />else<br />{<br /> $error = $db->errorInfo();<br /> echo "error happened..".$error[2];<br /> exit();<br />}<br /><br />$numpage = $total%$perpage;<br />if($total%$perpage) $numpage++;<br />$cur = $offset;<br />if ($cur < $numpage)<br />{<br /> echo "<a href ='". htmlentities($_SERVER['PHP_SELF'])."?offset = ".($cur+1)."'> Next Page</a><br />";<br />}<br />if($cur > 0)<br />{<br /> echo "<a href ='". htmlentities($_SERVER['PHP_SELF'])."?offset =". ($cur-1)."'> Prev Page</a><br />";<br /><br />}<br /><br /><br />?><br />