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.
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.
[ATTACH type="full" width="671px" alt="votes_working.png"]5415[/ATTACH]
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]
