My mod wasn't intended for statistics, it was designed for ease of use and simplicity. I believe I have accomplished that and I will not make any further modifications. Sorry to disappoint you.

It finally hit me earlier yesterday. The way I have it set up is all the ratings go in a commonpool.

##              +----------+------------------+------+-----+---------+-------+
##              | Field    | Type             | Null | Key | Default | Extra |
##              +----------+------------------+------+-----+---------+-------+
##              | rate     | tinyint(2)       |      |     | 0       |       |
##              | user_id  | int(10) unsigned |      |     | 0       |       |
##              | topic_id | int(10) unsigned |      |     | 0       |       |
##              +----------+------------------+------+-----+---------+-------+

The overall rating for a topic is not stored; only the individual ratings from a person. So if two people vote for the same topic, it is possible that it could show up twice. What you would have to do is select all distinct topic_id and then individually calculate the averages. To find top 5 you would have to store results in an array and do a lot more querying.

Ok, the update is now available http://www.punres.org/download.php?id=1081

This update allows the user to view the rating in viewtopic.php

I've decided to just upload the another file and not make a complete new release. I'll tell you when I'm done.

Sorry that I can't help, like I said, I don't know about merging tables, sorting, and all that stuff. I have recieved a couple emails requesting that the rating be shown in viewtopic.php. I contemplated doing this while I was creating it and decided against it because it would be a lot of code copying and pasting and I was trying to keep it simple and easy for the user to install. I can tell you it is quite simple to modify this, but I haven't decided whether I am going to do so and upload it because then I would probably release it as 1.1 and I haven't really made a way for the user to upgrade and right now the only option is removing it and then uploading a new version, thereby deleting all the rated topics sad. If I do decide to update, I'll post it here.

mystic wrote:
ORDER BY 'id'

I think you're accidentally getting the id in ascending order, that's why it will always show the same subject. this should work (i hope, sql isn't my specialty)

$resultb = $db->query('SELECT rate, topic_id, subject  FROM '.$db->prefix.'Ratings ORDER BY rate DESC LIMIT 5 ') or error('Unable to fetch user data', __FILE__, __LINE__, $db->error());
while ($datab = $db->fetch_assoc($resultb))
{
echo "".'<li><a href="http://xxxx/Forum/viewtopic.php?id='.$datab['topic_id'].'">'.pun_htmlspecialchars($datab['subject']).'</a></li> '.""; 
}

very cool! smile

nice big_smile

9

(114 replies, posted in Programming)

Textpad

##
##
##        Mod title:  Rate Topic
##
##      Mod version:  1.00
##   Works on PunBB:  1.2.* (meaning only small modifications of version 1.2 eg. 1.2.1)
##     Release date:  2006-09-09
##           Author:  Eric Subach A.K.A. Kha0sK1d (kha0s@comcast.net)
##
##      Description:  This mod allows non-guest users who run MySQL or MySQLi to rate any topic on a scale of 1 - 5 with 5
##                    being the best. Users may also view who voted for a particular topic and what they rating they gave.
##
##  Difference with
## previous version:  N/A
##
##   Affected files:  viewforum.php, viewtopic.php
##                    
##       Affects DB:  Yes
##                    Adds the table 'Ratings':
##              +----------+------------------+------+-----+---------+-------+
##              | Field    | Type             | Null | Key | Default | Extra |
##              +----------+------------------+------+-----+---------+-------+
##              | rate     | tinyint(2)       |      |     | 0       |       |
##              | user_id  | int(10) unsigned |      |     | 0       |       |
##              | topic_id | int(10) unsigned |      |     | 0       |       |
##              +----------+------------------+------+-----+---------+-------+
##                    Adds the following options to the table 'config':
##                    - o_rt_enabled
##                    - o_rt_use_stars
##                    - o_rt_cur_version
##                    - o_rt_cur_stars
##                    - o_rt_default_lang
##
##            Notes:  - Only MySQL and MySQLi are currently supported.
##                    - Purging or altering your database will cause Rate
##                      Topic to work improperly and may cause errors.
##                    - Ratings by banned members will not count so long as
##                      their ban is in effect.
##                    - Administrators have the following options:
##                      - Enable or disable Rate Topic
##                      - Use star images or numbers
##                      - Default language
##                      - Image packages
##                    - Having no star image packages will cause Rate Topic
##                      to default to using numbers.
##                    - Having corrupt star image packages will not cause
##                      PunBB to error, may yield images that do not display.
##                    - Guests may not vote or see who voted for a topic, but
##                      they may see the rating for a topic.
##                    - If a Rate Topic language file is not found, some pages
##                      will display an error, and others will justdefault to
##                      disabling Rate Topic.
##                    - If you decide to uninstall Rate Topic, run the
##                      install_mod.php file and click the restore button. You
##                      may choose to either remove the code that was added
##                      into viewforum.php and viewtopic.php, but it is not
##                      necessary for PunBB to continue working properly.
##                    - If you want to remove all ratings, uninstall Rate
##                      Topic and then install it again.
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##
##

Download here

11

(26 replies, posted in Programming)

http://www.w3schools.com

References, tutorials, etc.

Great job, jo jo, this mod rocks!

I don't think you could make this as an AMP mod, it would require actually modifying some of the current pages. I presume it wouldn't be difficult.