Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 418
0 Users 5 Guests Online

Thread Post Count

First of all the SQL
Code

ALTER TABLE `forum_thread` ADD `posts` VARCHAR( 225 ) NOT NULL default '0',



Next we need the code to add the post to the forum so in forum.php find this bit of code
PHP Code
1
2
3
4
5
6
7
8
9
<?PHP
case 'addreply':
$id htmlspecialchars($_POST[id]);
$message htmlspecialchars($_POST[message]);
$insert mysql_query("INSERT INTO `forum_posts` (`message`, `poster`, `thr_id`) VALUES ('$message', '$logged[username]', '$id')");
echo (
"Thanks for your reply. <br><a href='javascript: history.go(-1)'>Go back.</a>");
break; 
 
?>


And then change it to
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?PHP
case 'addreply':
$id htmlspecialchars($_POST[id]);
$message htmlspecialchars($_POST[message]);

$fetch_posts mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$id'");
$posts mysql_fetch_array($fetch_posts)//Gets the posts from the select thread

$posts2 $posts[posts]+1;//Adds 1 post to the forum post cound

$insert mysql_query("INSERT INTO `forum_posts` (`message`, `poster`, `thr_id`, `posts`) VALUES ('$message', '$logged[username]', '$id', '$posts2')");
echo (
"Thanks for your reply. <br><a href='javascript: history.go(-1)'>Go back.</a>");
break; 
 
?>



Next displaying the posts out on the main part :D
Im going to make a new line under the title and have my post count there...But you can change yours to be where ever you like :D

So find:
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?PHP
$threadmessage 
"$thread[message]";
$bbctm BBCODE($threadmessage);

echo (
"<tr>
<td id='mains'>&nbsp;</td>"
);
if(
$thread[sticky] == Yes)
{
echo (
"<td id='mains'><b>Sticky:</b> $bbctt2</td></tr>");
}
else
{
echo (
"<td id='mains'><b>$bbctt2</b></td></tr>"); 
 
?>



And change it to

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?PHP
$threadpcount 
"$thread[posts]"// Gets the post count

$threadmessage "$thread[message]";
$bbctm BBCODE($threadmessage);

echo (
"<tr>
<td id='mains'>&nbsp;</td>"
);
if(
$thread[sticky] == Yes)
{
echo (
"<td id='mains'><b>Sticky:</b> $bbctt2<em>$threadpcount - Posts</em></td></tr>");//Displays post count
}
else
{
echo (
"<td id='mains'><b>$bbctt2</b> <em>$threadpcount - Posts</em></td></tr>"); 
 
?>



Just a quick tutorials any problems comment below and until then if you have any more requests just PM me or gimmi a shout on the shoutbox when im online..Until then
Bon Voyage!
MOD-Dan
Author:
Views:
3214
Rating:
Posted on Saturday 6th September 2008 at 09:46 PM
JakkyD
JakkyD
Can someone help me, it's updating the posts but just doesnt show the actualy post itself.

This is my forumdisplay:

$threadpcount = "$thread[posts]"; // Gets the post count

$threadmessage = "$thread[message]";
$bbctm = BBCODE($threadmessage);

echo ("<tr>
<td id='mains'>&nbsp;</td>");
if($thread[sticky] == Yes)
{
echo ("<td id='mains'><b>Sticky:</b> $bbctt2<em>$threadpcount - Posts</em></td></tr>");//Displays post count
}
else
{
echo ("<td id='mains'><b>$bbctt2</b> <em>$threadpcount - Posts</em></td></tr>");
}

And addreply:

case 'addreply':
$id = htmlspecialchars($_POST[id]);
$message = htmlspecialchars($_POST[message]);

$fetch_posts = mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$id'");
$posts = mysql_fetch_array($fetch_posts);//Gets the posts from the select thread

$posts2 = $posts[posts]+1;//Adds 1 post to the forum post cound

$posts2 = $posts[posts]+1;
$do = mysql_query("UPDATE `forum_thread` SET `posts` = '$posts2' WHERE `id` = '$id'");

$insert = mysql_query("INSERT INTO `forum_posts` (`message`, `poster`, `thr_id`, `posts`) VALUES ('$message', '$user', '$id', '$posts2')");
echo ("Thanks for your reply. <br><a href='javascript: history.go(-1)'>Go back.</a>");
break;
Posted on Tuesday 1st January 2008 at 11:19 PM
new2old
new2old
Sorry couldn't edit in the addreply case change it to

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
case 'addreply':
$id = htmlspecialchars($_POST[id]);
$message = htmlspecialchars($_POST[message]);

$fetch_posts = mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$id'");
$posts = mysql_fetch_array($fetch_posts)//Gets the posts from the select thread

$posts2 = $posts[posts]+1;//Adds 1 post to the forum post cound

$do = mysql_query("UPDATE `forum_thread` SET `posts` = '$posts2' WHERE `id` = '$id'");

$insert = mysql_query("INSERT INTO `forum_posts` (`message`, `poster`, `thr_id`, `posts`) VALUES ('$message', '$logged[username]', '$id', '$posts2')");
echo ("Thanks for your reply. <br><a href='javascript: history.go(-1)'>Go back.</a>");
break;


instead
Posted on Tuesday 1st January 2008 at 11:17 PM
new2old
new2old
Fixed:
Code
ALTER TABLE `forum_thread` ADD `posts` VARCHAR( 225 ) NOT NULL default '0'


in forum.php in the addreply case replace it with

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
case 'addreply':
$id = htmlspecialchars($_POST[id]);
$message = htmlspecialchars($_POST[message]);

$fetch_posts = mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$id'");
$posts = mysql_fetch_array($fetch_posts)//Gets the posts from the select thread

$posts2 = $posts[posts]+1;//Adds 1 post to the forum post cound

$posts2 = $posts[posts]+1;
$do = mysql_query("UPDATE `forum_thread` SET `posts` = '$posts2' WHERE `id` = '$id'");

$insert = mysql_query("INSERT INTO `forum_posts` (`message`, `poster`, `thr_id`, `posts`) VALUES ('$message', '$logged[username]', '$id', '$posts2')");
echo ("Thanks for your reply. <br><a href='javascript: history.go(-1)'>Go back.</a>");
break;


again in forum but in the forumdisplay part
find and replace with
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$threadpcount = "$thread[posts]"; // Gets the post count

$threadmessage = "$thread[message]";
$bbctm = BBCODE($threadmessage);

echo ("<tr>
<td id='mains'>&nbsp;</td>");
if($thread[sticky] == Yes)
{
echo ("<td id='mains'><b>Sticky:</b> $bbctt2<em>$threadpcount - Posts</em></td></tr>");//Displays post count
}
else
{
echo ("<td id='mains'><b>$bbctt2</b> <em>$threadpcount - Posts</em></td></tr>");
Posted on Friday 19th October 2007 at 06:37 PM
Arudis
Arudis
SQL query:

ALTER TABLE `forum_thread` ADD `posts` VARCHAR( 225 ) NOT NULL default '0',

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Posted on Saturday 22nd September 2007 at 07:14 AM
Dalez
Dalez
I got that so.. i tookthe "," out at the end... and now myne is not working "/
Posted on Tuesday 21st August 2007 at 06:02 AM
-=InSaNe=-
-=InSaNe=-
phpMyAdmin does not work,

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

is the error. Why?
Posted on Saturday 18th August 2007 at 02:41 AM
-=InSaNe=-
-=InSaNe=-
Ill say it again, SQL does not work,

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

is the error. Why?
Posted on Sunday 1st July 2007 at 04:12 AM
-=InSaNe=-
-=InSaNe=-
Uhh, SQL does not work :S
Posted on Monday 25th June 2007 at 11:35 PM
ShadowMage
ShadowMage
it shows how many entries are in the selected table like users say would have say 500 or w/e.
Posted on Monday 25th June 2007 at 08:12 PM
SkillMaster
SkillMaster
mysql num rows just the the number of rows?