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

#1
[eluser]neph[/eluser]
just posted my source for the early stages of a forum, it's currently functional though.
wiki

#2
[eluser]darkhouse[/eluser]
The link is a mailto.

#3
[eluser]neph[/eluser]
fixed, thanks.

#4
[eluser]darkhouse[/eluser]
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.

Code:
$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";

#5
[eluser]neph[/eluser]
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...

Code:
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.

#6
[eluser]Dam1an[/eluser]
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

#7
[eluser]neph[/eluser]
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.

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

#9
[eluser]TheFuzzy0ne[/eluser]
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.

#10
[eluser]neph[/eluser]
am i missing something?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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