Topic: Rate Topic 1.0

##
##
##        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

Making the world a better place one byte at a time.

Re: Rate Topic 1.0

hi;

is it possible to show the post with the most rating ?

thanks

I love sky - i love flowers - and i love myself :D

Re: Rate Topic 1.0

<?php

$resulta = $db->query('SELECT subject FROM '.$db->prefix.'topics  ORDER BY `id`  ') or error('Unable to fetch user data', __FILE__, __LINE__, $db->error());
$dataa = $db->fetch_assoc($resulta);

$resultb = $db->query('SELECT rate, topic_id  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($dataa['subject']).'</a></li> '.""; 
}

?>

i just try to use this one so it can show the highest rate topic, however it always just appear all the same subject though.. eventhough it sort the topics with the rate right...can anyone know how to fix it please?

I love sky - i love flowers - and i love myself :D

4 (edited by Kha0sK1d 2006-10-21 23:11)

Re: Rate Topic 1.0

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> '.""; 
}
Making the world a better place one byte at a time.

Re: Rate Topic 1.0

following your code; in the Ratings table doesnt have subject though sad thanks for your reply btw

I love sky - i love flowers - and i love myself :D

6

Re: Rate Topic 1.0

then you would have to merge it with a table that does have subject. smile hope i cleared things up for you lol

Re: Rate Topic 1.0

Tubby wrote:

then you would have to merge it with a table that does have subject. smile hope i cleared things up for you lol

i know what u mean and i tried it already; but it just shows random subject instead...

$resultb = $db->query('SELECT *  FROM '.$db->prefix.'Ratings AND '.$db->prefix.'topics 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> '.""; 
}

thanks for your reply

I love sky - i love flowers - and i love myself :D

Re: Rate Topic 1.0

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.

Making the world a better place one byte at a time.

Re: Rate Topic 1.0

I'll post the join query later on, but now I have something else to do smile

10

Re: Rate Topic 1.0

elbekko wrote:

I'll post the join query later on, but now I have something else to do smile

im waitting for you smile thanks

I love sky - i love flowers - and i love myself :D

Re: Rate Topic 1.0

$result = $db->query("SELECT t.poster, t.subject, r.rate FROM ".$db->prefix."topics AS t JOIN ".$db->prefix."ratings AS r ON t.id=r.topic_id ORDER BY r.rate DESC LIMIT 5") or error('Unable to fetch ranked topics', __FILE__, __LINE__, $db->error());

I think this should do it smile I suppose you know how to get the data from the query tongue

Re: Rate Topic 1.0

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

Making the world a better place one byte at a time.

13

Re: Rate Topic 1.0

great man wink good luck with that; still waiting tongue

I love sky - i love flowers - and i love myself :D

Re: Rate Topic 1.0

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

Making the world a better place one byte at a time.

15

Re: Rate Topic 1.0

cool u are my god <3 thanks a lot

I love sky - i love flowers - and i love myself :D

16 (edited by mystic 2006-10-22 21:54)

Re: Rate Topic 1.0

Here is my code now

<? $resulta = $db->query('SELECT t.id, t.poster, t.subject, r.topic_id , r.rate FROM '.$db->prefix.'topics AS t JOIN '.$db->prefix.'Ratings AS r ON t.id=r.topic_id ORDER BY r.rate DESC LIMIT 5') or error('Unable to fetch ranked topics', __FILE__, __LINE__, $db->error()); 
while ($dataa = $db->fetch_assoc($resulta))
{
echo "".'<li><a href="http://xxxxx/Forum/viewtopic.php?id='.$dataa['topic_id'].'">'.pun_htmlspecialchars($dataa['subject']).'</a></li> '.""; 
}
?>

the subject, it apears right on main page, however (again).... some of the topic just show 2 times, it should be only 1 time for each toping beacuse it was orderred by rate and DESC LIMIT...

I wonder what did i do wrong?

Thanks for youre reply

I love sky - i love flowers - and i love myself :D

Re: Rate Topic 1.0

Unless topics can get multiple ratings it shouldn't be any problem =/

18

Re: Rate Topic 1.0

elbekko wrote:

Unless topics can get multiple ratings it shouldn't be any problem =/

I know it whould be fine; but i cant fine why it like that. I dont think the topic can get multiple ratings, it only can get one for each member....

I love sky - i love flowers - and i love myself :D

Re: Rate Topic 1.0

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.

Making the world a better place one byte at a time.

Re: Rate Topic 1.0

Or you could update your mod to do it decently tongue

Make topic_id unique, and use an INSERT INTO ... ON DUPLICATE KEY UPDATE query.

21

Re: Rate Topic 1.0

aye thanks for reply.... i know nothing about mysql... so i think have to give up the top rate...

I love sky - i love flowers - and i love myself :D

22 (edited by elbekko 2006-10-23 19:36)

Re: Rate Topic 1.0

I have some free time on my hands; I suppose I can update your mod for you smile

EDIT: Or even better, I'll just recreate it tongue

23

Re: Rate Topic 1.0

*my hope is coming back ... * tongue

I love sky - i love flowers - and i love myself :D

Re: Rate Topic 1.0

Almost done, just creating the readme now (sigh, that takes long even with the generator I made -.-).

25

Re: Rate Topic 1.0

Kha0sK1d wrote:

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.

u gonna have a new release? i hope so... if will; i hope it will be included some functions or tables that can show the top rate wink

I love sky - i love flowers - and i love myself :D