Index: lsrc.helper.php
===================================================================
--- lsrc.helper.php	(revision 8570)
+++ lsrc.helper.php	(working copy)
@@ -354,23 +354,34 @@
                  * - if not: send reminders normally
                  */
                  
-                $remSQL = "SELECT tid, remindercount "
-                . "FROM ".db_table_name("tokens_{$surveyid}")." "
-                . "WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent <>'' AND token <>'' AND EMAIL <>'' "
-                . "ORDER BY remindercount desc LIMIT 1";
-                $remResult = db_execute_assoc($remSQL);
-                $remRow = $remResult->FetchRow();
+               	$remSQL = "SELECT tid, remindercount "
+			. "FROM ".db_table_name("tokens_{$surveyid}")." "
+			. "WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent <>'' AND token <>'' AND EMAIL <>'' "
+			. "ORDER BY remindercount desc LIMIT 1";
+
+		$this->debugLsrc("Executing SQL: ".$remSQL);
+
+		$remResult = db_execute_assoc($remSQL);
+		$remRow = $remResult->FetchRow();
+
+		/* Get the reminder count from the row, if we have a row.  If 
+		 * we don't have a row then we set reminderCount to 0 to prevent
+		 * queries down below from bombing out. */
+		$reminderCount = $remRow['remindercount'];
+		if(empty($reminderCount)) {
+			$this->debugLsrc("There are no reminders to send.");
+			$reminderCount = 0;
+		}
+			
+		$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", remind ".$remRow['tid']."; ".$reminderCount." ");
+		
+		$sendOnlySQL = "SELECT tid, remindercount "
+		. "FROM ".db_table_name("tokens_{$surveyid}")." "
+		. "WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent <>'' AND token <>'' AND EMAIL <>'' AND remindercount < ".$reminderCount." "
+		. "ORDER BY tid asc LIMIT 1";
+
+		$this->debugLsrc("Executing SQL: ".$sendOnlySQL) 
                  
-                $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", remind ".$remRow['tid']."; ".$remRow['remindercount']." ");
-                 
-                $sendOnlySQL = "SELECT tid, remindercount "
-                . "FROM ".db_table_name("tokens_{$surveyid}")." "
-                . "WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent <>'' AND token <>'' AND EMAIL <>'' AND remindercount < ".$remRow['remindercount']." "
-                . "ORDER BY tid asc LIMIT 1";
-                $sendOnlyResult = db_execute_assoc($sendOnlySQL);
-                 
-                 
-                 
                 if($sendOnlyResult->RecordCount()>0)
                 {
                     $sendOnlyRow = $sendOnlyResult->FetchRow();
@@ -4346,4 +4357,4 @@
         }
         return "".$iCountParticipants."Datasets given, ".$iInsertedParticipants." rows inserted. ";
     }
-}
\ No newline at end of file
+}
