Welcome Guest, Not a member yet? Register   Sign In
Improve Topic Counts for Forum?
#1

[eluser]nullsys[/eluser]
Hi all,
Just a quick one I'm hoping you can help with.
I'm considering the "best" way to count the total topics within a category, all stored in MySQL.

Schema:

Categories
----------
id, name, description

Topics
----------
id, cat_id, subject

There is a relationship between topics.cat_id and categories.id

I'm currently using:

Code:
$id = 1;

public function count_all_results($id)
{
  $this->db->where('cat_id', $id);
  $this->db->from('topics');
  return $this->db->count_all_results();
}

This is working well, but I can't help think there is another "better way" because I may also want other data like "Last post by:" or "Last Topic:".
1. Storing the number of topics along side the category data in the table "categories".
2. Using another table with just topic and post counts.

Any suggestions would be greatly appreciated, thanks!


Messages In This Thread
Improve Topic Counts for Forum? - by El Forum - 07-03-2012, 03:20 AM
Improve Topic Counts for Forum? - by El Forum - 07-03-2012, 03:31 AM
Improve Topic Counts for Forum? - by El Forum - 07-03-2012, 03:51 AM
Improve Topic Counts for Forum? - by El Forum - 07-03-2012, 04:25 AM
Improve Topic Counts for Forum? - by El Forum - 07-03-2012, 04:40 AM
Improve Topic Counts for Forum? - by El Forum - 07-03-2012, 05:20 AM
Improve Topic Counts for Forum? - by El Forum - 07-03-2012, 05:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB