-4

该文件包含在我的索引文件中,我希望页面上和帖子 1 2 3 4... 等下的帖子不超过 5 个(链接到下一页),并且看起来像这样 index.php?page= 2 对不起我的语法不好。

    <?php
    if(isset($_GET['post_edit'])) {
    $p_id = $_GET['post_edit'];

    $p_query = mysql_query("SELECT title, post FROM posts WHERE id='$p_id'");
    $p_array = mysql_fetch_array($p_query);
    $title = $p_array['title'];
    $post = $p_array['post'];
    }
    ?>

    <?php
    if(isset($_POST['edit'])){
        $title_edit = $_POST['titleedit'];
        $post_edit = $_POST['postedit'];

    if(empty($title) or empty($post)){
        echo "<p>Fields empty!</p>";
        } else {
        mysql_query("UPDATE posts SET title='$title_edit', post='$post_edit' WHERE id='$p_id'");
        echo "Edit succesful!</br>";
        header('location: index.php');
    }
    }
    ?>

    <?php
    if(isset($_GET['post_edit']) && !empty($_GET['post_edit'])){
    include 'edit_post.php';
    } else {

    ?>
    <?php

    $query = mysql_query("SELECT * FROM posts ORDER BY date DESC");
        while($row = mysql_fetch_array($query)){


    echo "<div class='poststitle'>";
        echo "<div style='font-weight: bold;'>";
            echo $row['title'];
        echo "</div>";
    echo "</div>";

    echo "<div class='posts'>";
        echo $row['post'];
        echo "</br>";
        echo "<hr>";

        $user_name = mysql_query("SELECT username FROM users WHERE id = '".$row['user']."' ");
        $user_name_array = mysql_fetch_array($user_name);
            $post_id = $row['id'];

        echo "Posted by: <b>";
        echo $user_name_array['username'];
        echo "</b> | ";

        echo "Views: <b>";
        echo $row['views'];
        echo "</b> | ";

        echo "Posted on: ";
        echo "<b>";
        echo $row['date'];
        echo "</b><hr>";

    echo '</div>';

    if (loggedin()){
    if($user_level == 1){
        echo "<div class='postoptions'>";
        echo "<a href='index.php?post_edit=$post_id'><img src='img/optionicons/edit.png' width='15' height='15' alt='edit' /></a>";
        echo "<a href='del_post.php?del=$post_id'><img src='img/optionicons/cancel.png' width='15' height='15' alt='Delete' /></a>";
        echo "</div>";
        } else {
        echo "";
        }
    }
}
}
?>
4

2 回答 2

0

您应该LIMIT在 MySQL 查询中使用该子句,请参阅文档

为了计算 rof 页面数,您还需要总行数,可以使用 找到SQL_CALC_FOUND_ROWS,请参阅文档此问题

于 2013-07-31T10:07:41.650 回答
0

SELECT * FROM table_name 限制 N, M

其中 N - 有限行数和 M(offset) = N * (PAGE -1)

于 2013-07-31T10:13:59.890 回答