Jump to content

Recommended Posts

Hi,

I am making a forum and struggling to sum up posts.

I already have a code that perfectley shows Categorys and forums. What It displays is;

Cat - 1

Forum -1

Forum - 2

 

I want it to display this;

Cat - 1

Forum -1 ----- 3 Posts

Forum - 2 ----- 8 Posts

 

I want the code that shows the forums to add up the column replycount in the table topics where forumid is the same as the forums ID (so topics.forumid = forums.id).

 

If you need any more info please ask, thanks

 

PS. This is were I want to put it... http://dannyluked.comze.com/forum

Link to comment
https://forums.phpfreaks.com/topic/185523-sum-of-columns/
Share on other sites

Thanks for the reply.

The table structure for topics;

topicname | forumid | postcount

Topic - 1    |      10

Topic - 2    |        3

 

I want the postcount to be added up and shown next to the correct forum. This is the qry I have so far to show forums and categorys;

 

mysql_query("SELECT forum.*, forum.id AS fid, cat.*, Deriv1.fforumcount
FROM cat 
LEFT OUTER JOIN forum ON cat.id = forum.catid
LEFT OUTER JOIN (SELECT catid, count(forum.id) AS fforumcount FROM forum GROUP BY catid) Deriv1 ON cat.id = Deriv1.catid
WHERE forum.forumlevel = 5
ORDER BY forum.catid, forum.id ASC")

 

Link to comment
https://forums.phpfreaks.com/topic/185523-sum-of-columns/#findComment-979794
Share on other sites

I think you may not fully uderstand me! I need to add this query;

SELECT *, SUM(replycount) FROM topics GROUP BY forumid

 

Into this;

SELECT forum.*, forum.id AS fid, cat.*, Deriv1.fforumcount, topics.*, SUM(replycount)
FROM cat, topics
LEFT OUTER JOIN forum ON cat.id = forum.catid
LEFT OUTER JOIN (SELECT catid, count(forum.id) AS fforumcount FROM forum GROUP BY catid) Deriv1 ON cat.id = Deriv1.catid
WHERE forum.forumlevel = 5
ORDER BY forum.catid, forum.id ASC

 

I think that should make it easier!

Link to comment
https://forums.phpfreaks.com/topic/185523-sum-of-columns/#findComment-980147
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.