douduan2272 2013-06-07 00:14
浏览 19

确定哪个页面帖子属于

I'm making a little forum just for fun and practice probably never gonna put it in action, I'm not a real php guru it's just a hobby of mine. Right now I'm working on the edit post function. Everything is perfect except one thing I'm trying to figure out and that is how to redirect the user to his forum post after I *he have edited it. Like all the professional forums.

I show 10 posts per page...

Anyways this is how far I have come. Now I know how many pages the topic has but the thing I'm trying to figure out is how determine which page the specific post is on. And to be honest I have no idea. Tried google but I can't find anything helpful. Don't really know what to search for.

I sort posts by date BTW. Please let me know if you need any more info. Hopefully someone can point me in the right direction. Perhaps you have a better idea how to redirect to the post. I'm gonna look into PDO soon :) Please don't hate.

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");

The tables look like this:

topics
id | subject | postdate | forum_id

posts
id | poster_id | message | postdate | topic_id
  • 写回答

2条回答 默认 最新

  • dryl34156 2013-06-07 01:02
    关注
    $pagenumber = intval($postnumber / 10); //assuming 10 posts per page
    
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗