Use countSumTotalData() instead of SQL query
authorRoland Häder <roland@mxchange.org>
Wed, 9 Jan 2013 22:20:07 +0000 (22:20 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 9 Jan 2013 22:20:07 +0000 (22:20 +0000)
inc/libs/earning_functions.php
inc/modules/frametester.php
inc/modules/guest/what-mediadata.php
inc/referral-functions.php

index 3f747490bfa1fd97e3aa5250c057ecf301444c42..a1bb9a79f74048f3cf3d1fd00acc67111eb89349 100644 (file)
@@ -87,18 +87,8 @@ function generateMemberEarningDataTable ($earningProvider) {
 
 // Handle earning id
 function doMemberEarning ($earningId, $dailyAmount, $isActive = 'Y') {
-       // Does the user already have this earning?
-       $result = SQL_QUERY_ESC("SELECT COUNT(`id`) AS `cnt` FROM `{?_MYSQL_PREFIX?}_user_earning` WHERE `earning_id`=%s AND `earning_userid`=%s LIMIT 1",
-               array(
-                       bigintval($earningId),
-                       getMemberId()
-               ), __FUNCTION__, __LINE__);
-
-       // Get the count
-       list($count) = SQL_FETCHROW($result);
-
        // Does the user have this?
-       if ($count == 1) {
+       if (countSumTotalData(bigintval($earningId), 'user_earning', 'id', 'earning_id', TRUE, ' AND `earning_userid`=' . getMemberId()) == 1) {
                // Then update it
                $status = updateMemberEarning($earningId, $dailyAmount, $isActive);
        } else {
@@ -106,9 +96,6 @@ function doMemberEarning ($earningId, $dailyAmount, $isActive = 'Y') {
                $status = insertMemberEarning($earningId, $dailyAmount, $isActive);
        }
 
-       // Free result
-       SQL_FREERESULT($result);
-
        // Return status
        return $status;
 }
index 93c5eb126a212c20ac7e5fff3b88ab9ccfba84a1..09898ff036a0818c34be7ee2463df0cef1fb2e98 100644 (file)
@@ -46,13 +46,13 @@ if (isGetRequestElementSet('order')) {
        // Order number placed, is he also logged in?
        if (isMember()) {
                // Ok, test passed... :)
-               $result = SQL_QUERY_ESC("SELECT `subject`, `url` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s AND `sender`=%s AND `data_type`='TEMP' LIMIT 1",
+               $result = SQL_QUERY_ESC("SELECT `url` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s AND `sender`=%s AND `data_type`='TEMP' LIMIT 1",
                        array(bigintval(getRequestElement('order')), getMemberId()), __FILE__, __LINE__);
 
                // Finally is the entry valid?
                if (SQL_NUMROWS($result) == 1) {
                        // Load subject and URL (but forwhat do we need the subject line here???
-                       list($sub, $url) = SQL_FETCHROW($result);
+                       list($url) = SQL_FETCHROW($result);
 
                        // This fixes a white page
                        setPostRequestElement('url', $url);
index df1d0e8d7505c14f5458ed77caf489fb987471a1..8828b53ffda9d79ccc10ca11c9b51bd208a9a66c 100644 (file)
@@ -163,7 +163,7 @@ $content['total_logins']    = $logins;
 $total = countSumTotalData('Y', 'refbanner', 'id', 'visible', TRUE);
 
 // Total views and clicks
-$result = SQL_QUERY("SELECT SUM(`counter`) AS `cnt`, SUM(`clicks`) AS `clicks` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `visible`='Y'", __FILE__, __LINE__);
+$result = SQL_QUERY("SELECT SUM(`counter`) AS `views`, SUM(`clicks`) AS `clicks` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `visible`='Y'", __FILE__, __LINE__);
 list($views, $clicks) = SQL_FETCHROW($result);
 SQL_FREERESULT($result);
 
index 20b3da01690ebee3faaeb6300f7f129fecf48f36..1b95e84ee9c49cd3ee8cc1090f0e4b7e9a36923d 100644 (file)
@@ -699,12 +699,7 @@ function flushReferralTableToDatabase ($userid) {
                foreach ($levelArray as $refid) {
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . $refid);
                        // Query the user_refs table
-                       list($count) = SQL_FETCHROW(SQL_QUERY_ESC('SELECT COUNT(`id`) AS `count` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `level`=%s AND `refid`=%s LIMIT 1',
-                               array(
-                                       $userid,
-                                       $level,
-                                       $refid
-                               ), __FUNCTION__, __LINE__));
+                       $count = countSumTotalData(bigintval($userid), 'user_refs', 'id', 'userid', TRUE, ' AND `level`=' . bigintval($level) . ' AND `refid`=' . bigintval($refid));
 
                        // Is there no entry?
                        if ($count == 0) {