Welcome Guest, Not a member yet? Register   Sign In
mySQL count question
#8

[eluser]jedd[/eluser]
Correct - I thought I had, but I don't have it in my git repository, so maybe I just dreamt it.

Actually I think I ended up not caring about the number of messages in a whole forum, and considered message-counts-per-thread to be cheap enough to do on the fly.

In any case, yes, you can keep a message count in your forum table. This gets messy, of course, as any de-normalising does - consider extra code you have to write for thread deletes, thread moves, message deletes and message moves.

Btw, I forgot to mention, but your code:
Code:
$query = $this->db->query('SELECT forumtopics.id AS topicid, forumtopics.*,
COUNT(forummessages.topic_id) AS total_replies FROM forummessages, forumtopics
WHERE forummessages.topic_id = forumtopics.id  AND forumtopics.category_id =
'.$this->uri->segment(3).' GROUP BY forummessages.topic_id');

- is unsafe. Escape or sanity-check (an is_numeric() would be sufficient) the uri->segment(3) before feeding it into a SQL query, otherwise you're wide open to injection attacks.


Messages In This Thread
mySQL count question - by El Forum - 12-30-2009, 01:00 PM
mySQL count question - by El Forum - 12-30-2009, 01:06 PM
mySQL count question - by El Forum - 12-30-2009, 04:33 PM
mySQL count question - by El Forum - 12-30-2009, 05:44 PM
mySQL count question - by El Forum - 12-30-2009, 06:27 PM
mySQL count question - by El Forum - 12-30-2009, 09:05 PM
mySQL count question - by El Forum - 12-30-2009, 10:28 PM
mySQL count question - by El Forum - 12-31-2009, 06:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB