Thread Post Count


First of all the SQL
PHP Code
  1. 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. <?PHP
  2. case 'addreply':
  3. $id = htmlspecialchars($_POST[id]);
  4. $message = htmlspecialchars($_POST[message]);
  5. $insert = mysql_query("INSERT INTO `forum_posts` (`message`, `poster`, `thr_id`) VALUES ('$message', '$logged[username]', '$id')");
  6. echo ("Thanks for your reply. <br><a href='javascript: history.go(-1)'>Go back.</a>");
  7. break;
  8. ?>


And then change it to
PHP Code
  1. <?PHP
  2. case 'addreply':
  3. $id = htmlspecialchars($_POST[id]);
  4. $message = htmlspecialchars($_POST[message]);
  5.  
  6. $fetch_posts = mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$id'");
  7. $posts = mysql_fetch_array($fetch_posts)//Gets the posts from the select thread
  8.  
  9. $posts2 = $posts[posts]+1;//Adds 1 post to the forum post cound
  10.  
  11. $insert = mysql_query("INSERT INTO `forum_posts` (`message`, `poster`, `thr_id`, `posts`) VALUES ('$message', '$logged[username]', '$id', '$posts2')");
  12. echo ("Thanks for your reply. <br><a href='javascript: history.go(-1)'>Go back.</a>");
  13. break;
  14. ?>



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. <?PHP
  2. $threadmessage = "$thread[message]";
  3. $bbctm = BBCODE($threadmessage);
  4.  
  5. echo ("<tr>
  6. <td id='mains'>&nbsp;</td>");
  7. if($thread[sticky] == Yes)
  8. {
  9. echo ("<td id='mains'><b>Sticky:</b> $bbctt2</td></tr>");
  10. }
  11. else
  12. {
  13. echo ("<td id='mains'><b>$bbctt2</b></td></tr>");
  14. ?>



And change it to

PHP Code
  1. <?PHP
  2. $threadpcount = "$thread[posts]"; // Gets the post count
  3.  
  4. $threadmessage = "$thread[message]";
  5. $bbctm = BBCODE($threadmessage);
  6.  
  7. echo ("<tr>
  8. <td id='mains'>&nbsp;</td>");
  9. if($thread[sticky] == Yes)
  10. {
  11. echo ("<td id='mains'><b>Sticky:</b> $bbctt2<em>$threadpcount - Posts</em></td></tr>");//Displays post count
  12. }
  13. else
  14. {
  15. echo ("<td id='mains'><b>$bbctt2</b> <em>$threadpcount - Posts</em></td></tr>");
  16. ?>



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's Avatar
Author:
Views:
3,480
Rating:
Posted on Saturday 6th September 2008 at 09:46 PM
JakkyD
JakkyD's Avatar
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's Avatar
Sorry couldn't edit in the addreply case change it to

PHP Code
  1. case 'addreply':
  2. $id = htmlspecialchars($_POST[id]);
  3. $message = htmlspecialchars($_POST[message]);
  4.  
  5. $fetch_posts = mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$id'");
  6. $posts = mysql_fetch_array($fetch_posts)//Gets the posts from the select thread
  7.  
  8. $posts2 = $posts[posts]+1;//Adds 1 post to the forum post cound
  9.  
  10. $do = mysql_query("UPDATE `forum_thread` SET `posts` = '$posts2' WHERE `id` = '$id'");
  11.  
  12. $insert = mysql_query("INSERT INTO `forum_posts` (`message`, `poster`, `thr_id`, `posts`) VALUES ('$message', '$logged[username]', '$id', '$posts2')");
  13. echo ("Thanks for your reply. <br><a href='javascript: history.go(-1)'>Go back.</a>");
  14. break;


instead
Posted on Tuesday 1st January 2008 at 11:17 PM
new2old
new2old's Avatar
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. case 'addreply':
  2. $id = htmlspecialchars($_POST[id]);
  3. $message = htmlspecialchars($_POST[message]);
  4.  
  5. $fetch_posts = mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$id'");
  6. $posts = mysql_fetch_array($fetch_posts)//Gets the posts from the select thread
  7.  
  8. $posts2 = $posts[posts]+1;//Adds 1 post to the forum post cound
  9.  
  10. $posts2 = $posts[posts]+1;
  11. $do = mysql_query("UPDATE `forum_thread` SET `posts` = '$posts2' WHERE `id` = '$id'");
  12.  
  13. $insert = mysql_query("INSERT INTO `forum_posts` (`message`, `poster`, `thr_id`, `posts`) VALUES ('$message', '$logged[username]', '$id', '$posts2')");
  14. echo ("Thanks for your reply. <br><a href='javascript: history.go(-1)'>Go back.</a>");
  15. break;


again in forum but in the forumdisplay part
find and replace with
PHP Code
  1. $threadpcount = "$thread[posts]"; // Gets the post count
  2.  
  3. $threadmessage = "$thread[message]";
  4. $bbctm = BBCODE($threadmessage);
  5.  
  6. echo ("<tr>
  7. <td id='mains'>&nbsp;</td>");
  8. if($thread[sticky] == Yes)
  9. {
  10. echo ("<td id='mains'><b>Sticky:</b> $bbctt2<em>$threadpcount - Posts</em></td></tr>");//Displays post count
  11. }
  12. else
  13. {
  14. 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's Avatar
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's Avatar
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=-'s Avatar
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=-'s Avatar
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=-'s Avatar
Uhh, SQL does not work :S
Posted on Monday 25th June 2007 at 11:35 PM
ShadowMage
ShadowMage's Avatar
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's Avatar
mysql num rows just the the number of rows?