More rewrites to make use of (cached) wrapper functions
[mailer.git] / inc / libs / sponsor_functions.php
index 76296b04e9743e337a4296953d98e6edf9c277d7..81810de1d1a09172836f1310bc037f2566f85b2d 100644 (file)
@@ -276,18 +276,32 @@ function addSponsorMenu ($current) {
        if (isAdmin()) $WHERE = '';
 
        // Load main menu entries
-       $result_main = SQL_QUERY("SELECT action AS main_action, title AS main_title FROM `{?_MYSQL_PREFIX?}_sponsor_menu`
-WHERE (`what`='' OR `what` IS NULL) ".$WHERE."
-ORDER BY `sort`", __FUNCTION__, __LINE__);
-       if (SQL_NUMROWS($result_main) > 0) {
+       $result_main = SQL_QUERY("SELECT
+       `action` AS `main_action`, `title` AS `main_title`
+FROM
+       `{?_MYSQL_PREFIX?}_sponsor_menu`
+WHERE
+       (`what`='' OR `what` IS NULL)
+       ".$WHERE."
+ORDER BY
+       `sort` ASC", __FUNCTION__, __LINE__);
+       if (!SQL_HASZERONUMS($result_main)) {
                // Load every menu and it's sub menus
                while ($content = SQL_FETCHARRAY($result_main)) {
                        // Load sub menus
-                       $result_sub = SQL_QUERY_ESC("SELECT what AS sub_what, title AS sub_title FROM `{?_MYSQL_PREFIX?}_sponsor_menu`
-WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ".$WHERE."
-ORDER BY `sort`",
+                       $result_sub = SQL_QUERY_ESC("SELECT
+       `what` AS `sub_what`, `title` AS `sub_title`
+FROM
+       `{?_MYSQL_PREFIX?}_sponsor_menu`
+WHERE
+       `action`='%s' AND
+       `what` != '' AND
+       `what` IS NOT NULL
+       ".$WHERE."
+ORDER BY
+       `sort` ASC",
                        array($content['main_action']), __FUNCTION__, __LINE__);
-                       if (SQL_NUMROWS($result_sub) > 0) {
+                       if (!SQL_HASZERONUMS($result_sub)) {
                                // Load sub menus
                                $SUB = '';
                                while ($content2 = SQL_FETCHARRAY($result_sub)) {