2011-04-16 66 views
0

我正在重寫我的通訊郵件,以限制發送到某些域。基本上用戶以另一種形式被保存在mailer_lists中,然後他們被分配郵件IP以使用該郵件IP對指定域的限制。下面的代碼是我收集這些信息的嘗試。從多個變量循環查詢?

我想要做的是拉記錄查詢匹配,循環通過$node_ip,$throttle_domain$throttle_speed,然後停止拉記錄,如果它達到全球限制,然後發送。我無法得到它的工作的權利..

function queue(){ 
$query = "SELECT * FROM `mailer_lists` WHERE `ip` = '$node_ip' AND `email` LIKE '%".$throttle_domain."' LIMIT ".$throttle_speed."" ; 
$result = mysql_query($query) or die(mysql_error()); 
$num_rows = mysql_num_rows($result); 
$count = $num_rows; 
} 
if ($count < $global){ 
queue(); 
}else{ 
mail(); 


希望我有1/2的技能你們中的一些有。期待任何想法..

回答

1

讓你發揮作用的行數回報這樣的:

function queue(){ 
$query = "SELECT * FROM `mailer_lists` WHERE `ip` = '$node_ip' AND `email` LIKE '%".$throttle_domain."' LIMIT ".$throttle_speed."" ; 
$result = mysql_query($query) or die(mysql_error()); 
return mysql_num_rows($result); 
} 

不,你可以讓你的病情:

if (queue() < $global){ 
queue(); 
}else{ 
mail(); 
+0

這看起來不錯,但我如何從下一個記錄中提取數據? $ throttle_domain可以包含數十個目標域,並且每個域都有它自己的$ throttle_speed。 – john 2011-04-16 22:03:36

+0

你是否想要一個返回行數的函數,並且結果呢? – SIFE 2011-04-16 22:11:05

+0

我想拉記錄,直到它達到$ global。 – john 2011-04-16 22:17:19

0

函數中的計數不被標記爲全局,因此不會更新。將全局$ count添加爲隊列函數的第一行。

另一個問題是,當計數從未達到全局變量時,它將永遠不會發送郵件。所以最後一批不會被髮送。

0

我真的不這是否會在所有的工作:d

<?php 

function queue($ptr, $glbl){ 
/* each time we increment our range by $glbl */ 
$newPtr = $ptr + 100; 
/* we use limit keyword to only fetch 100 rows each time */ 
$query = "SELECT * FROM `mailer_lists` WHERE `ip` = '$node_ip' LIMIT '$ptr', '$newPtr'" ; 
$result = mysql_query($query) or die(mysql_error()); 
/* fetch the rows and send to theme an email */ 
while($row = mysql_fetch_row($result)) 
{ 
    mail(mail($row['email'], $subject, $message)); 
} 

} 
/* here we use a static variable to track where we are we in the range */ 
static $next = 0; 
$i = 0; 
/* sending emails*/ 
queue($next, $glbl); 
/* put pur next beginning range in 
$next ant it will end with $next + $glbl as it in line 5 */ 
$next += $glbl; 
?>