MyBB Community Forums

Full Version: Replies to topic shows 1 instead of 0
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Yes, same database. I had converted locally, then uploaded it to server.

Script took a long time to execute. Is that normal? Also I'm using google SEO plugin by the way. Does that make any difference.
Also it got reverted to the old bug (1 reply instead of 0) when I ran the rebuild statistics from admin panel. :o
I'm trying to debug your script. Thanks for the help so far. I'll let you know whether I solved it.
see if firstpost is set to 0 for any threads. if so, fix that.
(2010-02-21, 05:31 PM)frostschutz Wrote: [ -> ]see if firstpost is set to 0 for any threads. if so, fix that.

Where do I check this?
Problem still not fixed. Any ideas?
PM me if I haven't replied here in 24 hours. Don't have time right now but will try later on.
Thanks. I will write a pure PHP/MySQL script to do the same what you tried with the MyBB functions.

I'm pretty sure that it SHOULD have worked as I analyzed your script, but somewhere the post count is mangled to -1. Very confusing. I think I am going to try the direct method as I'm not familiar enough with the MyBB database functions (learning a new interface for every database access is a barrier).
Well I fixed the problem with this pure PHP/MySQL code I wrote based on your pointers:

<?php
	$conn = mysql_connect ("localhost", "user", "password");
	if (! $conn ) die ("error in connection!");
	
	$ret = mysql_select_db ("database", $conn);
	if (! $ret ) die ("error selecting db!");
	
	$query1 = "select * from mybb_threads;";
	$res1 = mysql_query ($query1, $conn);	
	if (! $res1 ) die ("error executing query 1!");
	
	while ($row = mysql_fetch_assoc ($res1))
	{
		$query2 = "select * from mybb_posts where tid=" . $row['tid'] . ";";
		$res2 = mysql_query ($query2, $conn);
		if (! $res2 ) die ("error executing query 2!");
		
		$num = mysql_num_rows ($res2);
		
		$query3 = "update mybb_threads set replies=" . strval ($num - 1) . " where tid=" . $row['tid'] . ";";
		$res3 = mysql_query ($query3);
		if (! $res3 ) die ("error executing query 3!");
		
		mysql_free_result ($res2);

	}
	
	mysql_free_result ($res1);
	mysql_close ($conn);
		
?>

This worked on Localhost.

Thanks for pointing me in the right direction though. Much appreciated. Big Grin

Mind you I'm aware this is a very quick-n-dirty solution and I probably should have paid attention to other post factors like moderated posts which shouldn't show up in the post count anyway. Adding a simple extra parameter to filter out the moderated posts would probably be enough.
Pages: 1 2