0

我做一个小论坛只是为了好玩和练习可能永远不会把它付诸实践,我不是一个真正的 php 大师,这只是我的一个爱好。现在我正在研究编辑帖子功能。一切都很完美,除了我想弄清楚的一件事,那就是在我*他编辑它之后如何将用户重定向到他的论坛帖子。像所有的专业论坛一样。

我每页显示10个帖子...

无论如何,这就是我已经走了多远。现在我知道该主题有多少页,但我想弄清楚的是如何确定特定帖子在哪个页面上。老实说,我不知道。试过谷歌,但我找不到任何有用的东西。真的不知道要搜索什么。

我按日期排序帖子顺便说一句。如果您需要更多信息,请告诉我。希望有人能指出我正确的方向。也许您对如何重定向到帖子有更好的想法。我很快就会调查 PDO :) 请不要讨厌。

editpost.php

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;

// Fetch some info about the topic and/or the forum
$query = mysqli_query($link, "SELECT * FROM posts
                              WHERE id = $id");

// Someone pressed "Edit Post"
if (count($_POST) > 0) {
    // validate stuff
    update post...
}

// See if there is more than one pages so we can redirect to the correct message, how we are gonna know which page the post is on i have no idea
$totalCount = "SELECT COUNT(*) as 'Total' FROM posts WHERE topic_id = $row->topic_id";
$rsCount = mysqli_query($link, $totalCount) or die(mysqli_error($link));
$rowCount = mysqli_fetch_object($rsCount);
$numOfPages = ceil($rowCount->Total / 10);

// just now during development to see if it counted correct
// there is more than 10 posts so we must determine which page this post belongs on
if ($rowCount->Total > 10)
echo "Page: $numOfPages";

header("Location thread.php?id=$id&page=???#post$id");

表格如下所示:

topics
id | subject | postdate | forum_id

posts
id | poster_id | message | postdate | topic_id
4

2 回答 2

0
$pagenumber = intval($postnumber / 10); //assuming 10 posts per page
于 2013-06-07T01:02:51.220 回答
0

我知道了。

$totalCount = mysqli_query($link, "SELECT COUNT(*) as 'Total' FROM posts WHERE topic_id =           $row->topic_id AND posted < $row->posted");
$rowCount = mysqli_fetch_object($totalCount);
$page = ceil($rowCount->Total / 9);
$redirect = ($page > 1) ? "&page=$page#post$id" : "#post$id";
于 2013-06-07T01:37:25.057 回答