Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Rating: Why half working?
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / Torrent Trader / v3 Support

2020-03-30 10:04:13
Could someone please run down the logic of this code for me? I have it working perfectly across torrents & main index, except.. refuses to display my html for stars IF user has not voted yet (if no other votes are already saved from other users, otherwise its a white space). Wracking my brain over this.. I know the code is rough, because there were really long routines that didn't make sense and a lot of wasted lines.. but it works.

Problem: Does not show rating stars IF torrent has zero ratings yet from anybody. So a first time vote isn't possible. It was possible on the original code, that was a mess to work with.

Can anyone test this or at least assess what it may be?

Ignore the HTML, that is needed on my end.
// New AJAX Rating Feature - Jan 26, 2020
$total_votes = 0;
$total_value = 0;
$query       = SQL_Query_exec("SELECT COUNT(torrent) as total_votes, SUM(rating) as total_value FROM `ratings` WHERE `torrent` = '$id'");
while ($rating = mysql_fetch_array($query)) {
   $total_votes = $rating['total_votes'];
   $total_value = $rating['total_value'];
}
$voted = get_row_count("ratings", "WHERE `torrent` = '" . $id . "' AND `user` = '" . $CURUSER["id"] . "'");
if ($total_votes < 1) { // Require at least 1 vote to show votes to all
   $count = 0;
} else {
   $count = $total_votes;
}
$current_rating = $total_value;
$tense          = ($count == 1) ? "rating" : "ratings";
if (is_numeric($current_rating) && is_numeric($count)) {
   $rating_width = number_format($current_rating / $count, 2) * 30;
   $rating_1     = number_format($current_rating / $count, 1); // Vote result format: 2 = 5.00, 1 = 5.0, 0 = 5.  -  Jan 26 2020
   $rating_2     = number_format($current_rating / $count, 1);
}
if (!$voted) {
   $rater .= '<ul>';
   $rater .= '<div style="color:#242424;font-size:35px;font:arial,helvetica,sans-serif;margin-bottom:-48px;font-weight:400"><span style="font-weight:500">' . $rating_2 . '</span>/' . 5 . '</div>'; // For SCORE next to rating (eg. 4.7/5) - UL must stay here to align!
   for ($ncount = 1; $ncount <= 5; $ncount++) {

   // New rating stars work
   $rater .= '<li class="stars-rating" style="--rating: ' . $ncount . '; position:relative;" aria-label="rating: ' . $ncount . '/' . $units . '">
              <div style="position:absolute;top:56px;left:12px;"><a title="' . $ncount . ' out of ' . 5 . '" href="' . $site_config["SITEURL"] . '/torrents-details.php?id=' . $id . '&takerating=yes&j=' . $ncount . '" style="text-decoration:none;color:transparent">
              <span style="">?</span></a></div></li>';    
   }
   $ncount = 0;
   $rater .= '</ul>';
}

if ($voted) {
$static_rater = array();
$static_rater[] .= '<ul>';
$static_rater[] .= '<li class="stars-rating" style="--rating: ' . $rating_2 . '"><span style="color:#242424;font-size:35px;font:arial,helvetica,sans-serif;margin-bottom:-65px;font-weight:400"><span style="font-weight:500">' . $rating_2 . '</span>/' . 5 . '</span></li>';
$static_rater[] .= '</ul>';
$rater .= join("\n", $static_rater);
}

// rating
$rater .= '<span class="stars-rating" style="--rating: ' . $rating_1 . '"></span>Total: ' . $count . ' ' . $tense;


Working across ALL torrents (and viewing torrents that received other votes)
[ATTACH type="full" width="664px" alt="ratings_working.png"]5412[/ATTACH]

My own vote on a already-voted torrent (by someone else) works fine too
[ATTACH type="full" width="665px" alt="my_own_rating_working.png"]5413[/ATTACH]

Finally.. I can't vote worth crap. Nothing shows up, I see the CSS is there but how can it phase out the rest?
[ATTACH type="full" width="667px" alt="no_votes_impossible_to_vote.png"]5414[/ATTACH]

EDIT: Working. This is needed.

// Rating
if ($count >= 1){
$rater .= '<span class="stars-rating" style="--rating: ' . $rating_1 . '"></span>Total: ' . $count . ' ' . $tense;
}elseif ($count == 0){
$rater .= '<span class="stars-rating" style="--rating: 0.0"></span>';  
}


[ATTACH type="full" width="671px" alt="votes_working.png"]5415[/ATTACH]
ratings_working.png
ratings_working.png
my_own_rating_working.png
my_own_rating_working.png
no_votes_impossible_to_vote.png
no_votes_impossible_to_vote.png
votes_working.png
votes_working.png
2020-03-30 14:33:44
allo STorrents2020

You have to bandage to test with this renge there for the non vote?


// Rating
if ($count >= 1){
$rater .= '<span class="stars-rating" style="--rating: ' . $rating_1 . '"></span>Total: ' . $count . ' ' . $tense;
}elseif ($count == 0){
$rater .= '<span class="stars-rating" style="--rating: 0.0"></span>';
}else{
$rater .= '<span class="stars-rating" style="">0.0</span>';
}
//


I haven't tested your code on my test site, but it's an idea lol (y)
2020-03-31 03:17:21
"spiritblue, post: 68259, member: 401":

allo STorrents2020

You have to bandage to test with this renge there for the non vote?


// Rating
if ($count >= 1){
$rater .= '<span class="stars-rating" style="--rating: ' . $rating_1 . '"></span>Total: ' . $count . ' ' . $tense;
}elseif ($count == 0){
$rater .= '<span class="stars-rating" style="--rating: 0.0"></span>';
}else{
$rater .= '<span class="stars-rating" style="">0.0</span>';
}
//


I haven't tested your code on my test site, but it's an idea lol (y)


ill give this a try, thank you good tip!
2020-04-01 00:55:07
"spiritblue, post: 68259, member: 401":

allo STorrents2020

You have to bandage to test with this renge there for the non vote?


// Rating
if ($count >= 1){
$rater .= '<span class="stars-rating" style="--rating: ' . $rating_1 . '"></span>Total: ' . $count . ' ' . $tense;
}elseif ($count == 0){
$rater .= '<span class="stars-rating" style="--rating: 0.0"></span>';
}else{
$rater .= '<span class="stars-rating" style="">0.0</span>';
}
//


I haven't tested your code on my test site, but it's an idea lol (y)


This line is needed to be changed from [color=rgb(41, 105, 176)]$rating_2[/color] to [color=rgb(41, 105, 176)]$count[/color]:

$rater .= '<div style="color:#242424;font-size:35px;font:arial,helvetica,sans-serif;margin-bottom:-48px;font-weight:400"><span style="font-weight:500">' . $count . '</span>/' . 5 . '</div>';
2020-04-01 06:33:44
This has been updated with tooltips and fixes for if logged in or not, if anyone wants
2020-04-01 15:55:43
"STorrents2020, post: 68268, member: 20382":

This has been updated with tooltips and fixes for if logged in or not, if anyone wants

yesss, I'm taker please ;)
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 1
  • Members: 0
  • Guests online: 1
  • Comments: 3
  • Messages: 1,728