-$result_main = SQL_QUERY_ESC("SELECT d.id, d.userid, d.points, d.remote_ip, d.timemark
-FROM `{?_MYSQL_PREFIX?}_doubler` AS d
-LEFT JOIN `{?_MYSQL_PREFIX?}_user_data` AS u
-ON d.userid=u.userid
-WHERE u.`status`='CONFIRMED' AND d.points <= %s AND d.points >= %s AND d.completed='N' AND d.is_ref='N'
-ORDER BY d.timemark
-LIMIT %d",
+$result_main = SQL_QUERY_ESC("SELECT
+ d.id, d.userid, d.points, d.remote_ip, d.timemark
+FROM
+ `{?_MYSQL_PREFIX?}_doubler` AS d
+LEFT JOIN
+ `{?_MYSQL_PREFIX?}_user_data` AS u
+ON
+ d.userid=u.userid
+WHERE
+ u.`status`='CONFIRMED' AND
+ d.points <= %s AND
+ d.points >= ({?doubler_min?} * 2) AND
+ d.completed='N' AND
+ d.is_ref='N'
+ORDER BY
+ d.timemark ASC
+LIMIT {?doubler_max_sent?}",