我最近又回到了一些PHP編程,但已經陷入與PHP分頁的東西,似乎我試過的任何事情都會導致它不計算頁面和在結果的一頁上顯示,或者只是在第6頁停下來,並且不再進一步,我知道存儲在MySQL數據庫中的數據,它應該顯示52頁結果,每頁12個。PHP分頁不能正常工作,在第6頁停止
所以我需要一些幫助,我認爲這是有效的,直到我打入數據庫之後,將不會超過第100頁。
的代碼如下
<?php
//
//How to print date
//
if($print_date == 1)
{
$print_date = '%d.%m.%Y';
}
elseif($print_date == 2)
{
$print_date = '%m.%d.%Y';
}
elseif($print_date == 3)
{
$print_date = '%W, %M %D %Y';
}
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
} // if
$get_matches = mysql_query("SELECT
O.OpponentName AS hometeam, OP.OpponentName AS awayteam,
LM.LeagueMatchHomeGoals AS goals_home,
LM.LeagueMatchAwayGoals AS goals_away,
LM.LeagueMatchID AS id,
DATE_FORMAT(LM.LeagueMatchDate, '$print_date') AS date
FROM tplls_leaguematches LM, tplls_opponents O, tplls_opponents OP
WHERE O.OpponentID = LM.LeagueMatchHomeID AND
OP.OpponentID = LM.LeagueMatchAwayID AND
LeagueMatchSeasonID LIKE '$defaultseasonid'
ORDER BY LM.LeagueMatchDate");
$get_matches = @mysql_query($SQL) or die("Error Processing Fixtures");
$query_data = mysql_fetch_row($get_matches);
$numrows = $query_data[0];
$rows_per_page = 12;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
$pageno = $lastpage;
} // if
if ($pageno < 1) {
$pageno = 1;
} // if
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$get_matches2 = mysql_query("SELECT
O.OpponentName AS hometeam, OP.OpponentName AS awayteam,
LM.LeagueMatchHomeGoals AS goals_home,
LM.LeagueMatchAwayGoals AS goals_away,
LM.LeagueMatchID AS id,
DATE_FORMAT(LM.LeagueMatchDate, '$print_date') AS date
FROM tplls_leaguematches LM, tplls_opponents O, tplls_opponents OP
WHERE O.OpponentID = LM.LeagueMatchHomeID AND
OP.OpponentID = LM.LeagueMatchAwayID AND
LeagueMatchSeasonID LIKE '$defaultseasonid'
ORDER BY LM.LeagueMatchDate, hometeam $limit",$connection)
or die(mysql_error());
while($row = mysql_fetch_array($get_matches2))
{
?>
更多以添加,如果我拿出第一個SELECT語句,我得到了同樣的結果?
注意:如果您正在從事生產工作,您應該查看[mysqli](http://us.php.net/manual/en/book.mysqli.php)和[預先準備的語句](http:// us3 .php.net /手動/ EN/pdo.prepared-statements.php)。大多數教程吸吮!我發現[這篇文章在SitePoint上](http://www.sitepoint.com/perfect-php-pagination/)。我還沒有讀過它,但它看起來很有希望。 – Herbert
這似乎並不奏效,它引發了一個致命的錯誤。 致命錯誤:位於/home/vhosts/binfieldfc.com/httpdocs/leaguetables/firstteam/index2.php中的SQL行1688 – OuterHaven
這是行 1688 $ result = @mysql_query($ query)或trigger_error(「SQL」, E_USER_ERROR); – OuterHaven