Jump to content

Sum of columns...


dannyluked

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.