duanjia1870 2013-07-24 11:07 采纳率: 0%
浏览 16
已采纳

来自MySQL的PHP​​分页

I have problem with my paging PHP script. First page works perfectly, but next pages are blank. Config.php include database setting like host etc. Please help me solve my problem. Thanks in advance.

Here is my code:

include 'config.php';
mysql_connect($iplogow, $userlogow, $haslologow) or die("Mysql error: " . mysql_error());
mysql_select_db($bazalogow)or die("Błąd bazy danych: " . mysql_error());


        echo '<br>
            <table class="table table-bordered table-striped" width="500px">
               <thead>
                <tr>
                    <th>table1</th>
                    <th>table2</th>
                <th>table3</th>
                <th>table4</th>
                <th>table5</th>
                <th>table6</th>
                <th>table7</th>
                     </tr></thead>';


        $result = mysql_query("SELECT Count(id) FROM `logi`");
        $row = mysql_fetch_row($result);
        $count_users = $row[0];

        $per_page = 10;


        $pages = ceil($count_users / $per_page);


        $current_page = !isset($_GET['page']) ? 1 : (int)clear($_GET['page']);


        if($current_page < 1 || $current_page > $pages) {
            $current_page = 1;
        }


        if($count_users > 0) {
            $result = mysql_query("SELECT * FROM `logi` ORDER BY `id` DESC LIMIT ".($per_page*($current_page-1)).", ".$per_page);
            while($row = mysql_fetch_assoc($result)) {
                echo '<tr>
                    <td>'.$row['nick'].'</td>
                                <td>'.$row['ip'].'</td>
                    <td>'.$row['password'].'</td>
                    <td>'.$row['productid'].'</td>
                    <td>'.$row['client'].'</td>
                    <td>'.$row['date'].'</td>
                    <td>'.$row['hour'].'</td>
                </tr>';
            }
        } else {
            echo '<tr>
                <td colspan="3" style="text-align:center">Niestety nie znaleziono żadnych ataków.</td>
            </tr>';
        }
        echo '</table>';


        if($pages > 0) { 
            echo '<p>';
            if($pages < 11) {
                for($i = 1; $i <= $pages; $i++) {
                    if($i == $current_page) {
                        echo '<b>['.$current_page.']</b> ';
                    } else {
                        echo '<a href="ataki.php?page='.$i.'">['.$i.']</a> ';
                    }
                }
            } elseif($current_page > 10) {
                echo '<a href="ataki.php?page=1">[1]</a> ';
                echo '<a href="ataki.php?page=2">[2]</a> ';
                echo '[...] ';
                for($i = ($current_page-3); $i <= $current_page; $i++) {
                    if($i == $current_page) {
                        echo '<b>['.$current_page.']</b> ';
                    } else {
                        echo '<a href="ataki.php?page='.$i.'">['.$i.']</a> ';
                    }
                }
                for($i = ($current_page+1); $i <= ($current_page+3); $i++) {
                    if($i > ($pages)) break;
                    if($i == $current_page) {
                        echo '<b>['.$current_page.']</b> ';
                    } else {
                        echo '<a href="ataki.php?page='.$i.'">['.$i.']</a> ';
                    }
                }
                if($current_page < ($pages-4)) {
                    echo '[...] ';
                    echo '<a href="ataki.php?page='.($pages-1).'">['.($pages-1).']</a> ';
                    echo '<a href="ataki.php?page='.$pages.'">['.$pages.']</a> ';
                } elseif($current_page == ($pages-4)) {
                    echo '[...] ';
                    echo '<a href="ataki.php?page='.$pages.'">['.$pages.']</a> ';
                }
            } else {
                for($i = 1; $i <= 11; $i++) {
                    if($i == $current_page) {
                        if($i > ($pages)) break;
                        echo '<b>['.$current_page.']</b> ';
                    } else {
                        echo '<a href="ataki.php?page='.$i.'">['.$i.']</a> ';
                    }
                }
                if($pages > 12) {
                    echo '[...] ';
                    echo '<a href="ataki.php?page='.($pages-1).'">['.($pages-1).']</a> ';
                    echo '<a href="ataki.php?page='.$pages.'">['.$pages.']</a> ';
                } elseif($pages == 12) {
                    echo '[...] ';
                    echo '<a href="ataki.php?page=12">[12]</a> ';
                }
            }
            echo '</p>';
        }
        ?>
  • 写回答

1条回答 默认 最新

  • doushang1890 2013-07-24 11:28
    关注

    Have you included the clear() function?

    Look at line: $current_page = !isset($_GET['page']) ? 1 : (int)clear($_GET['page']);

    If you have not included the function then you will get a fatal error in the execution of the script. Try to remove the clear() all together and see what happens, the changed line should be

    $current_page = !isset($_GET['page']) ? 1 : $_GET['page'];

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line