Index: trunk/ippMonitor/def/autocode.php
===================================================================
--- trunk/ippMonitor/def/autocode.php	(revision 34011)
+++ trunk/ippMonitor/def/autocode.php	(revision 34012)
@@ -28,9 +28,5 @@
 // ** TABLE RESTRICTIONS **
 
-if ($restricted == 0) {
-  if ("$UNRESTRICTED" != "none") {
-    $WHERE = "$WHERE $UNRESTRICTED";
-  }
-}
+// Note: the restriction is now moved AFTER the count query
 
 // Add GROUP BY statements if any
@@ -56,4 +52,12 @@
   menu_end();
 }
+
+// Restrict the query if it is necessary
+if ($restricted == 0) {
+  if ("$UNRESTRICTED" != "none") {
+    $WHERE = "$WHERE $UNRESTRICTED";
+  }
+}
+
 // set up the row counter variables
 if ($ID['from']) {
