Jump to content

[SOLVED] Counting is generating more


Ashoar

Recommended Posts

Another problem  ;)

 

So this section of my code would count the amount of posts that were made within a certain board so i could then display them on the main page for each board.

It worked properly in an older version of php, but since upgrading to 5.2.9 i have run into a few errors.

What happens now, is the code is generating it's own amounts of posts.

For example:

I posted 3 threads in a board, just for testing. And own the main page it showed up as 9 threads, for that board.

 

In another board i made 1 thread, on the main page it showed up ad 4 for that board.

 

I know this is not a problem with the way my posts are being inserted into the database as i have a small information center which displays the correct amounts of posts for the whole board.

 

I have the feeling it has something to do with my array after fetching the mysql information, but i cannot find a solution for it.

 

This is the code for that particular section:

 

$boards = mysql_query("SELECT f.forum_name,
       f.forum_desc,
       f.board,
       COUNT(p.post) AS threads,
       MAX(p.showtime) AS showtime,
       MAX(p.lastposter) AS lastposter
  FROM forums AS f
       LEFT JOIN post_reply AS p ON p.board=f.board AND p.parentid='0'
GROUP BY f.forum_name,
          f.forum_desc,
          f.board
ORDER BY f.forum_id asc")  
or die(mysql_error());

$boards2 = mysql_num_rows($boards);
for($count = 1; $count <= $boards2; $count++)
{
$board = mysql_fetch_array($boards);

print "<tr class='mainrow'><td><center>On</center></td><td><A href='board.php?board=".$board['board']."'>".$board['forum_name']."</a><p>".$board['forum_desc']."</p></td><td><center>".$board['threads']."</center></td><td><center>".$board0['posts']."</center</td><td>On ".$board['showtime']."<br><br>By <A href='member_profile.php?username=$board[lastposter]'>$board[lastposter]</a></td></tr>";
}

 

Do you see anything within that snippet of code that could be causing this problem?

 

Thanks

 

 

Link to comment
Share on other sites

Are all the lines being output different and are they valid or are there duplicates and if so, post an example of what the output is and post what it should be. You are asking us to see what your are problem is without showing us what you see in front of you and providing a reference of what it should be.

 

What was the php version before it was upgraded and was anything else upgraded, like the mysql version or was the database backed up and restored to a different database server?

Link to comment
Share on other sites

The original version of PHP was just 5.2.* according the host i had it on.

That was a free host.

I then did a fresh install of my forum software onto my paid hosting account which is 5.2.9.

 

All the database tables were installed newly onto this host and all the php files were uploaded. So it was a fresh start.

 

Here is a picture of the thread column for a certain board:

CYAcox.jpg

That 9 should only be a 3, as their is only 3 threads within that board.

 

I also have another board which has 8 threads displayed on the main page, but it only has 2 threads made within it.

 

 

As said, this worked fine in the other version of php, so i would have to assume it is just a small thing that needs to be changed, but i cannot find the solution.

Link to comment
Share on other sites

Nothing in the code you posted is responsible for displaying the total number of threads. What is the actual code on the main page that gets and displays the thread count that you just showed?

 

Are the table rows that are output from the code you posted in the first post in this thread correct or not?

Link to comment
Share on other sites

The code i presented does.

" COUNT(p.post) AS threads,"

That gets the threads, which is post from the table.

 

"LEFT JOIN post_reply"

post_reply is the table with the posts/threads which is joined to the other table "forums" that way i can get the posts from certain boards.

 

As said this worked perfectly on the older version of php.

Link to comment
Share on other sites

The for() loop is just outputting data from your query. If you had fewer rows being output or rows with null/empty data, the for() loop could be at fault. But if $board['threads'] is where the number is coming from, that is produced by the query, unless you have some php code that is adding to that number that you have not shown. The problem is either in your actual data or it is a mysql/query problem.

 

Edit: If you actually had 9 posts, but only three links were being produced, then that could be a problem with the for() loop and the mysql_num_rows($boards) that set the count for the loop. Is there some reason why you are not just using a while() loop to iterate over the rows in the result set?

Link to comment
Share on other sites

I will go back and double check the post page but i don't believe it is the error.

As i said if i count the total amount of entries into that table i get the correct amount which shows in the database.

 

It just seems odd that it starts doing this after moving to a different version of php.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.