Commit:    a1f89f36cf8a3c77ae5c8b788b749913e4c07213
Author:    Sherif Ramadan <[email protected]>         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".


--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to