php - 下一个和上一个分页错误

标签 php mysql

我做了以下分页,每页打印 2 篇文章,但是当我按 2 或下一个时什么也没有发生

即使在我的脚本之上使用 error_reporting,我也完全没有错误

为什么页面链接或下一个按钮不起作用?

<?php
    error_reporting(E_ALL); ini_set("display_errors", 1);
    $db = mysql_connect("localhost", "root", "");
    mysql_select_db("dirts_mysql", $db);
    echo "<h1>articles</h1>";
    $pr_page = 2;
    $number = mysql_result(mysql_query("SELECT COUNT(*) FROM article WHERE category =                 1"), 0) or die(mysql_error());
    $show_from = (isset($_GET["visfra"]) && is_numeric($_GET["visfra"]) && $_GET["visfra"] < $number) ? $_GET["visfra"] : 0;
    $query = mysql_query("SELECT * FROM article ORDER BY id DESC limit $show_from,     $pr_page") or die(mysql_error());
    while ($row = mysql_fetch_array($query)) {
        ?>
        <link rel="stylesheet" type="text/css" href="style.css">
        <div id="news">
            <h2><u><? echo $row['name']; ?></u></h2>

            <p>
                <?php echo nl2br($row['description']); ?>...
            </p>
            <br/><br/>
            <a href="vis.php?id=<? print $row['id']; ?>">[...]</a>
        </div>
    <br>
    <?php
    }
    if ($show_from > 0) {
        $back = $show_from - $pr_page;
        echo "<a href='?showfrom=$back'>Forrige</a> ";
   }
    $page = 1;
    for ($start = 0; $number > $start; $start = $start + $pr_page) {
        if ($show_from != $page * $pr_page - $pr_page) {
            echo "<a href='?showfrom=$start'>$page</a> ";
        } else {
            echo $page . " ";
        }
    $page++;
    }
    if ($show_from < $number - $pr_page) {
        $next = $show_from + $pr_page;
        echo " <a href='?&showfrom=$next'>Næste</a>";
    }
    ?>

最佳答案

这是因为您正在链接中创建变量 showfrom:

    echo " <a href='?&showfrom=$next'>Næste</a>";

但是在读回值时引用 visfra

$show_from = (isset($_GET["visfra"]) && is_numeric($_GET["visfra"]) && $_GET["visfra"] < $number) ? $_GET["visfra"] : 0;

关于php - 下一个和上一个分页错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19705100/

相关文章:

php - Laravel 中的 Controller 无法识别由 JQuery 创建的表单元素

MySql 加载文件脚本和 2 个表

mysql - 在 AWS 中使用 liquibase 更新 MySQL 5.6.40 DD

php - 检查多行并返回是否全部匹配

php - 如何在 yii 1 中获取所有属性标签

php - 计数查询在 codeigniter 中不起作用

php - 无法加载 xdebug.so : undefined symbol: gc_globals

php - jQuery/Ajax PHP POST 调用

mysql - 单独序列表中的 JPA 主键

Mysql测试2个用户是否有对话