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