• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
forum written with codeigniter

just posted my source for the early stages of a forum, it's currently functional though.

The link is a mailto.

fixed, thanks.

I just quickly looked at the first bit of your forum model and noticed something. You're selecting all categories, then looping through each one selecting all of the threads in each category and adding the num_rows as numThreads to each category, then doing the same thing again for posts and adding the num_rows as numPosts to each category.

It probably doesn't make much difference now, but in the future if your forum is popular you could potentially be selecting many thousands of records here. This could end up taking a very long time to process each page request and your forum could become unusable. A much better solution is to let your database do all the work by using teh COUNT function.

Now I haven't tested this code, it's possible it might be a little more complex than what I've got here. You might need to use a subquery or something, but I'm sure it's very possible to get everything you want in one SQL statement and that will greatly reduce the load when you have a lot of data.

$sql = "SELECT c.*, COUNT(t.id) numThreads, COUNT(p.id) numPosts
        FROM fm_categories c
        JOIN fm_threads t ON t.categoryID = c.id
        JOIN fm_posts p ON p.threadId = t.id
        GROUP BY t.id, c.id";

yeah, when counting two fields i couldnt get them to return each's value, it would just set both counts as the highest of both. if count(cola) was 4 and count(colb) was 2 they would both return as 4...

mysql> SELECT c.*, COUNT(t.id) numThreads, COUNT(p.id) numPosts
    ->         FROM fm_categories c
    ->         JOIN fm_threads t ON t.categoryID = c.id
    ->         JOIN fm_posts p ON p.threadId = t.id
    ->         GROUP BY t.id, c.id;
| id | name               | description                           | privilege | active | numThreads | numReplies | numThreads | numPosts |
|  1 | General Discussion | This area is for general discussions. |         0 | 1      |          0 |          0 |          5 |        5 |
1 row in set (0.06 sec)

i know it's doable with a "union" but this was just easier for now, it's still needs a lot of work.

I've not looked through the source yet, but the demo looks nice Smile
I wonder why there has been a sudden interest in forums for CI lately

Edit: There doesn't appear to be a link for the source on the wiki page I had to go back to Feb to get a link to the source, but that'll be very outdated

i'm about to release an updated version using jquery-ui for ajaxish sorting and inline administration, proper ACL, thread e-mail notices/subscriptions, and tableless markup. shouldnt be more than a week or two until it's finished.

[eluser]Thorpe Obazee[/eluser]
Where's Fuzzy? Smile

Taking the night off. I've finally decided how I'm going to process, although I will have a look at it at some point.

am i missing something?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.