我正在制作一个只是为了娱乐和练习的小论坛,可能永远不会把它付诸行动,我不是一个真正的PHP大师,这只是我的一个爱好。现在我正在编辑编辑帖子功能。一切都很完美,除了我想弄清楚的一件事,那就是在我编辑之后如何将用户重定向到他的论坛帖子。像所有的专业论坛一样。
我每页显示10个帖子......
无论如何,这是我走了多远。现在我知道该主题有多少页面,但我想弄清楚的是如何确定特定帖子所在的页面。说实话,我不知道。尝试谷歌但我找不到任何有用的东西。真的不知道要搜索什么。
我按日期排序BTW。如果您需要更多信息,请与我们联系。希望有人可以指出我正确的方向。也许你有更好的想法如何重定向到帖子。我很快就会调查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
答案 0 :(得分:0)
$pagenumber = intval($postnumber / 10); //assuming 10 posts per page
答案 1 :(得分: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";