PHP MySQL分页mysqli_result()错误

时间:2017-03-16 11:29:52

标签: php mysql pagination

我正在进行分页,但它无效我尝试使用mysqli_fetch_array并尝试mysqli_result
如果你有什么想法,请指导我 对于分页页面,我尝试了一种方法,但我仍然遇到问题 这是我试过的代码,

<?php
$conn = mysqli_connect("localhost", "root", "", "vm");
include 'paginate.php';
$per_page      = 2;
$result        = mysqli_query($conn, "SELECT * FROM table1");
$total_results = mysqli_num_rows($result);
$total_pages   = ceil($total_results / $per_page);
if (isset($_GET['page'])) {
    $show_page = $_GET['page'];
    if ($show_page > 0 && $show_page <= $total_pages) {
        $start = ($show_page - 1) * $per_page;
        $end   = $start + $per_page;
    } else {
        $start = 0;
        $end   = $per_page;
    }
} else {
    $start = 0;
    $end   = $per_page;
}
$page   = intval($_GET['page']);
$tpages = $total_pages;
if ($page <= 0) {
    $page = 1;
}
function paginate($reload, $page, $tpages)
{
    $adjacents = 2;
    $prevlabel = "&lsaquo; Prev";
    $nextlabel = "Next &rsaquo;";
    $out       = "";
    // previous
    if ($page == 1) {
        $out .= "<span>" . $prevlabel . "</span>\n";
    } elseif ($page == 2) {
        $out .= "<li><a href=\"" . $reload . "\">" . $prevlabel . "</a>\n</li>";
    } else {
        $out .= "<li><a href=\"" . $reload . "&page=" . ($page - 1) . "\">" . $prevlabel . "   </a>\n</li>";
    }
    $pmin = ($page > $adjacents) ? ($page - $adjacents) : 1;
    $pmax = ($page < ($tpages - $adjacents)) ? ($page + $adjacents) : $tpages;
    for ($i = $pmin; $i <= $pmax; $i++) {
        if ($i == $page) {
            $out .= "<li class=\"active\"><a href=''>" . $i . "</a></li>\n";
        } elseif ($i == 1) {
            $out .= "<li><a href=\"" . $reload . "\">" . $i . "</a>\n</li>";
        } else {
            $out .= "<li><a href=\"" . $reload . "&page=" . $i . "\">" . $i . "</a>\n</li>";
        }
    }
    if ($page < ($tpages - $adjacents)) {
        $out .= "<a style='font-size:11px' href=\"" . $reload . "&page=" . $tpages . "\">" . $tpages . "</a>\n";
    }
    // next
    if ($page < $tpages) {
        $out .= "<li><a href=\"" . $reload . "&page=" . ($page + 1) . "\">" . $nextlabel . " </a>\n</li>";
    } else {
        $out .= "<span style='font-size:11px'>" . $nextlabel . "</span>\n";
    }
    $out .= "";
    return $out;
}

提前致谢。

0 个答案:

没有答案