Ashoar Posted April 13, 2009 Share Posted April 13, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/153854-solved-counting-is-generating-more/ Share on other sites More sharing options...
ober Posted April 13, 2009 Share Posted April 13, 2009 ".$board0['posts']." Why is there a 0 in there? Quote Link to comment https://forums.phpfreaks.com/topic/153854-solved-counting-is-generating-more/#findComment-808599 Share on other sites More sharing options...
Ashoar Posted April 13, 2009 Author Share Posted April 13, 2009 Oh, no that is not the problem, it is this one ".$board['threads']." The one you pointed out is from a different table, it does not effect the current problem. Quote Link to comment https://forums.phpfreaks.com/topic/153854-solved-counting-is-generating-more/#findComment-808605 Share on other sites More sharing options...
PFMaBiSmAd Posted April 13, 2009 Share Posted April 13, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/153854-solved-counting-is-generating-more/#findComment-808629 Share on other sites More sharing options...
Ashoar Posted April 13, 2009 Author Share Posted April 13, 2009 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: 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. Quote Link to comment https://forums.phpfreaks.com/topic/153854-solved-counting-is-generating-more/#findComment-808640 Share on other sites More sharing options...
PFMaBiSmAd Posted April 13, 2009 Share Posted April 13, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/153854-solved-counting-is-generating-more/#findComment-808657 Share on other sites More sharing options...
Ashoar Posted April 13, 2009 Author Share Posted April 13, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153854-solved-counting-is-generating-more/#findComment-808664 Share on other sites More sharing options...
Ashoar Posted April 14, 2009 Author Share Posted April 14, 2009 Just pushing this back to the first page. Once again, i think the error may be with the array, for statement: for($count = 1; $count <= $boards2; $count++) Quote Link to comment https://forums.phpfreaks.com/topic/153854-solved-counting-is-generating-more/#findComment-809211 Share on other sites More sharing options...
PFMaBiSmAd Posted April 14, 2009 Share Posted April 14, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/153854-solved-counting-is-generating-more/#findComment-809221 Share on other sites More sharing options...
Ashoar Posted April 14, 2009 Author Share Posted April 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153854-solved-counting-is-generating-more/#findComment-809228 Share on other sites More sharing options...
Ashoar Posted April 14, 2009 Author Share Posted April 14, 2009 Seems that this was an error with the database. I removed the table and then re installed and it worked fine. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/153854-solved-counting-is-generating-more/#findComment-809273 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.