Hey guys, I'm trying to create my own forums and Ive been fairly successful with it.
The only problem is I decided to only allow 5 posted to be displayed per page. If there are more the 5 posts the code should break them down in to sets of 5 and display them on different pages..
//a custom function that I have in an include function earlier
forum_db_con();
//$_GET['forumname'] is passed through the url when they click into one.
$table = $_GET['forumname'];
if (isset($_GET[“page”]))
{
$page = $_GET[“page”];
}
else
{
$page=1;
};
$start_from = ($page-1) * 20;
$query = mysql_query("SELECT * FROM $table ORDER BY id DESC LIMIT $start_from, 5");
<hr />
while($row = mysql_fetch_assoc($query))
{
$id = $row['id'];
$name = $row['Name'];
$date = $row['Date'];
$Comments = $row['Comments'];
//giving the posts different backgrounds so theyre distinguishable
if ($id%2)
$bgcolor = "./Imgs/background.png";
else
$bgcolor = "./Imgs/forumbg.png";
//starting to echo out the posts
echo "
<table style=\"background-image:url('$bgcolor')\" width = 85% align =\"center\">";
echo
"<tr>
<td width = 100%><b>$name</b> posted on $date<br /><hr /></td>
</tr>
<tr>
<td>" . nl2br(strip_tags($Comments)) . "</td>
</tr>";
}
echo "</table>";
<hr />
//counting how many posts are stored in my database
$sql = mysql_query("SELECT COUNT(id) FROM $table");
$rows = mysql_fetch_row($sql);
$total_records = $rows[0];
//dividing the posts into 5's
$total_pages = ceil($total_records / 5);
//echoing out the page numbers... this is where the problem seems to be happening..
for ($i=1; $i<=$total_pages; $i++)
{
echo "<a href=\"helpforum.php?page=".$i."&forumname=".$table."\">".$i."</a> ";
}
//this is where I have the reply/post forum not sure if its helpful..
if (isset($_POST['submit']))
{
$name = $_POST['Name'];
$Comments = $_POST['Comments'];
$date = date("Y-m-d");
if($name&&$Comments)
{
$querypost = mysql_query("INSERT INTO $table VALUES ('' , '$name' , '$date' , '$Comments')");
echo "<div align=\"center\"><b>Please wait...<meta http-equiv='refresh' content='2'></b></div>";
}
else
{
echo "Please fill in all feilds";
}
}
if($_SESSION['username'])
{
echo"
<form action=\"helpforum.php?forumname=$table\" method='POST'>
<table align = \"center\">
<tr>
<td>Your name:</td>
<td><input type='text' name='Name' /></td>
</tr>
<tr>
<td>Your Comment:</td> <td><textarea name='Comments'></textarea></td>
</tr>
<tr>
<td><input type='submit' name='submit' value='Post' /></td></tr>
</table>
</form>";
}
else
{
echo "<div align=\"center\"><b>Due to recent spamers you must login to post in forums... <br />
Sorry for any inconviences</b></div>";
}
Well thats all the code..
Here is a link to the actual site testing page that the code is fun http://tikiwebproductions.com/helpforum.php?forumname=helpforum
There are 6 posts total so there shuold be 5 that show, then when you click the "2" hyperlink at the bottom it should refresh the page with the other post...
I've been looking at this for 2 days and cant figure it out..