Computer ForumsComputers  

Go Back   Computer Forums > Programmers Lounge > Programming Discussions

Reply
 
LinkBack Thread Tools Display Modes
Old 09-10-2004, 10:17 AM   #1 (permalink)
Newb Techie
 
Join Date: Mar 2004
Posts: 36
Send a message via AIM to DKasler Send a message via Yahoo to DKasler
Default Average rating (Help with topic rating script)

Ok, i have this topic rating script on my forum, and I hate the way it rates the post.. I rates them like this...

Code:
<option value='2'>Excellent!</option>
<option value='1'>Very Good</option>
<option value='0'>Not Sure</option>
<option value='-1'>I Don't Like It</option>
<option value='-2'>God...I Hate It</option>
So basically +2 stars for an excellent rating, and -2 for the worst rating... Kind of pointless, since if the 1st rating is the worst no stars will even show up until atleast 1 Excellent, and 1 good rating are added to the topic.

I tried changing the option values to 5, 4, 3, 2, and 1 but that didnt really work with the vote.php which is below.

Any ideas how to make the below code do an average of all the topic ratings done on it?

Like one rating of 4, and one rating of 2 will yeild 3 stars...

Any help would be GREATLY Appreciated. Thanks so much.

Code:
$idx = new Vote;

class Vote {

var $output     = "";
var $page_title = "";
var $nav        = array();
var $html       = "";
function Vote(){
global $ibforums, $std, $print, $DB;
$ibforums->lang = $std->load_words($ibforums->lang, 'lang_error', $ibforums->lang_id );
// lets check u havn't already voted in this topic
$DB->query("select * from ibf_topicratings where topicid='{$ibforums->input['topic']}' and mvoter='{$ibforums->member['id']}'");
if($DB->get_num_rows() == 0){
// havn't voted here before, lets make it count :D
$DB->query("select * from ibf_topics where tid='{$ibforums->input['topic']}'");
$topic=$DB->fetch_row();
$topic['rating']+=$ibforums->input['vote'];

if($topic['rating'] > 5){
$topic['rating']=5;
}elseif($topic['rating'] < 0){
$topic['rating']=0;
}else{
$topic['rating']=$topic['rating'];
}

$DB->query("update ibf_topics set rating='{$topic['rating']}' where tid='{$ibforums->input['topic']}'");
// log your vote
$DB->query("insert into ibf_topicratings VALUES ('','{$ibforums->input['topic']}','{$ibforums->member['id']}')");

$print->redirect_screen("Rating Updated", "showtopic=".$ibforums->input['topic'],0);
} else {
// already voted
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'all_ready_vote' ) );
}
}

// End Class
}

DKasler is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 03:57 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0