dannyluked Posted December 17, 2009 Share Posted December 17, 2009 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 More sharing options...
dannyluked Posted December 17, 2009 Author Share Posted December 17, 2009 I will look be able to reply to any help tommorow at about 17:00 British time. (latest) Link to comment https://forums.phpfreaks.com/topic/185523-sum-of-columns/#findComment-979490 Share on other sites More sharing options...
fenway Posted December 18, 2009 Share Posted December 18, 2009 Post the table structure... should be as simple as a count90. Link to comment https://forums.phpfreaks.com/topic/185523-sum-of-columns/#findComment-979586 Share on other sites More sharing options...
dannyluked Posted December 18, 2009 Author Share Posted December 18, 2009 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 More sharing options...
cags Posted December 18, 2009 Share Posted December 18, 2009 I think you will just need to add... COUNT(forumid) as post_count ... to the items your selecting, and probably... GROUP BY forumid Link to comment https://forums.phpfreaks.com/topic/185523-sum-of-columns/#findComment-979801 Share on other sites More sharing options...
emopoops Posted December 18, 2009 Share Posted December 18, 2009 cags is really on the money today i agree with her. cant go wroing with what she stated in aforementioned post Link to comment https://forums.phpfreaks.com/topic/185523-sum-of-columns/#findComment-979955 Share on other sites More sharing options...
dannyluked Posted December 18, 2009 Author Share Posted December 18, 2009 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 More sharing options...
emopoops Posted December 18, 2009 Share Posted December 18, 2009 or u could just mysql_result each Link to comment https://forums.phpfreaks.com/topic/185523-sum-of-columns/#findComment-980149 Share on other sites More sharing options...
dannyluked Posted December 18, 2009 Author Share Posted December 18, 2009 I'm just a beginner! Could you go into more detail please Link to comment https://forums.phpfreaks.com/topic/185523-sum-of-columns/#findComment-980158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.