Computers |
|
| | #1 (permalink) |
| Newb Techie | 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> 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
} |
| | |