duanchi5078 2011-08-30 07:16
浏览 30
已采纳

PHP分页无法正常运行,在第6页停止

I've recently got back into doing some PHP coding but have got stuck on something with PHP Pagination, it would seem that anything I tried either results in it not counting the pages and displaying on one page of results, or just stops at Page 6 and goes no further, I know with the data that is stored in the MySQL database, it should be showing 52 pages of results at 12 per page.

So I'm in need of some help, I thought it was working until I hit the won't go further than Page 6 after putting in 100's of entires into the database.

The code is as follows

<?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))
    {
?>

More to add, if I take out the first SELECT statement, I get the same result?

  • 写回答

2条回答 默认 最新

  • duanqian9593 2011-08-30 09:08
    关注

    Try this out. It's just your code with some minor modifications.

    <?php
        //
        //How to print date
        //
        switch ($print_date)
        {
        case 1:
            $print_date = '%d.%m.%Y';
            break;
        case 2:
            $print_date = '%m.%d.%Y';
            break;
            case 3:
            $print_date = '%W, %M %D %Y';
        }
    
        if (isset($_GET['pageno'])) {
            $pageno = $_GET['pageno'];
        } else {
            $pageno = 1;
        } // if
    
        $clause = "
            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";
    
        $query = "SELECT COUNT(*) as num $clause";
        $result = @mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
        $r = mysql_fetch_row($result);
        $numrows = $r[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;
    
        $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 $clause $limit";
    
        $get_matches = mysql_query($query, $connection)
            or die(mysql_error());
        while($row = mysql_fetch_array($get_matches))
        {
    ?>
    

    It's actually what @g.salakirov suggested but in the context of all the code you supplied. I haven't tested it, but it should work. (Famous last words. :D)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 angular开发过程中,想要读取模型文件,即图1的335行,会报404错误(如图2)。但我的springboot里配置了静态资源文件,如图3。且在该地址下我有模型文件如图4,请问该问题该如何解决呢?
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 vite打包后,页面出现h.createElement is not a function,但本地运行正常
  • ¥15 Java,消息推送配置
  • ¥15 Java计划序号重编制功能,此功能会对所有序号重新排序,排序后不改变前后置关系。
  • ¥15 关于哈夫曼树应用得到一些问题