]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/refback_functions.php
More rewrites/templates swapped out:
[mailer.git] / inc / libs / refback_functions.php
index 5dc539c2e7ad52e091f99f3de2770139ce2b1386..dcd553bf1724a546d801a1ae7ec7dfc672f689ec 100644 (file)
@@ -52,7 +52,7 @@ function addRefbackPoints ($userid, $ref, $points, $ref_points) {
        $return = $points;
 
        // Get all ref levels
-       $result_refs = SQL_QUERY("SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level` > 0 ORDER BY `level` ASC",
+       $result_refs = SQL_QUERY('SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level` > 0 ORDER BY `level` ASC',
                __FUNCTION__, __LINE__);
 
        // "Walk" through all level
@@ -114,30 +114,33 @@ function getRefbackPercents ($userid, $ref) {
        // Skip identical ids
        if ($userid == $ref) return 0;
 
-       // Default is zero
-       $percents = '0';
-
-       // Get percents from database
-       $result = SQL_QUERY_ESC("SELECT refback FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `refid`=%s LIMIT 1",
-       array($ref, $userid), __FUNCTION__, __LINE__);
-
-       // Entry found? (Should be!)
-       if (SQL_NUMROWS($result) == 1) {
-               // Fetch percents
-               list($percents) = SQL_FETCHROW($result);
-               //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):percents={$percents}<br />");
-       } else {
-               // Debug log
-               //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>): NO ENTRY FOUND! :-(<br />");
-               logDebugMessage(__FUNCTION__, __LINE__, "userid={$userid},ref={$ref} - No entry found! :-(");
-       }
-
-       // Free result
-       SQL_FREERESULT($result);
+       // Is it cached?
+       if (!isset($GLOBALS['refback_percents'][$userid][$ref])) {
+               // Default is zero
+               $GLOBALS['refback_percents'][$userid][$ref] = '0';
+
+               // Get percents from database
+               $result = SQL_QUERY_ESC("SELECT `refback` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `refid`=%s LIMIT 1",
+                       array($ref, $userid), __FUNCTION__, __LINE__);
+
+               // Entry found? (Should be!)
+               if (SQL_NUMROWS($result) == 1) {
+                       // Fetch percents
+                       list($GLOBALS['refback_percents'][$userid][$ref]) = SQL_FETCHROW($result);
+                       //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>):percents=".$GLOBALS['refback_percents'][$userid][$ref]."<br />");
+               } else {
+                       // Debug log
+                       //* DEBUG: */ print(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__."</font>): NO ENTRY FOUND! :-(<br />");
+                       logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ' - No entry found! :-(');
+               }
+
+               // Free result
+               SQL_FREERESULT($result);
+       } // END - if
 
        // Return percents
        //* DEBUG: */ print("</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />");
-       return $percents;
+       return $GLOBALS['refback_percents'][$userid][$ref];
 }
 
 // "Getter" for userid array which will return only one entry