com web/master: Fixed rating calculation in notes search view. Not all queries select the rate.: manage/user-notes.php
| From: | Sherif Ramadan | Date: | Tue, 25 Dec 2012 06:25:10 +0000 |
| Subject: | com web/master: Fixed rating calculation in notes search view. Not all queries select the rate.: manage/user-notes.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-15144@lists.php.net to get a copy of this message | ||
Commit: a1f89f36cf8a3c77ae5c8b788b749913e4c07213
Author: Sherif Ramadan <googleguy@php.net> Tue, 25 Dec 2012 01:25:10 -0500
Parents: 01525ef163b4249367a50795bc25395639a41f4c
Branches: master
Link: http://git.php.net/?p=web/master.git;a=commitdiff;h=a1f89f36cf8a3c77ae5c8b788b749913e4c07213
Log:
Fixed rating calculation in notes search view. Not all queries select the rate.
Changed paths:
M manage/user-notes.php
Diff:
diff --git a/manage/user-notes.php b/manage/user-notes.php
index 02462d7..b94db6a 100644
--- a/manage/user-notes.php
+++ b/manage/user-notes.php
@@ -276,7 +276,18 @@ if (!$action) {
} else {
$rating = "<span style=\"color:
blue;\">$rating</span>";
}
- $percentage = sprintf('%d%%',$row['rate']);
+
+ if (isset($row['rate'])) { // not all queries select the rate
+ $percentage = $row['rate'];
+ } else {
+ if ($row['up'] + $row['down']) { // prevents division by zero
warning
+ $percentage = $row['up'] / ($row['up'] +$row['down']);
+ } else {
+ $precentage = 0;
+ }
+ }
+ $percentage = sprintf('%d%%', $percentage);
+
echo "<div style=\"float: right; clear: both; border: 1px solid gray;
padding: 5px; background-color: lightgray;\">\n".
"<div style=\"display: inline-block; float: left; padding:
15px;\"><strong>Up votes</strong>: {$row['up']}</div>\n".
"<div style=\"display: inline-block; float: left; padding:
15px;\"><strong>Down votes</strong>:
{$row['down']}</div>\n".