2011-02-07 21 views
1

由於你在這個線程中大部分人都知道,我有使用for循環和if語句發送大容量短信的問題。然而,我已經減少了我的查詢以下。我只使用AND的重複和每次免疫日期PHP不執行所有給定的語句

$getnumbers="SELECT 
    guardian_records.First_Name, 
    guardian_records.ID, 
    guardian_records.Cellphone_Number, 
    children_records.Child_First_Name, 
    children_records.Guardian_ID, 
    children_records.ID, 
    immunization_records.child_ID, 
    immunization_records.First_Immunization_Date,   
FROM 
    guardian_records, 
    children_records, 
    immunization_records 
WHERE 
    guardian_records.ID = children_records.Guardian_ID 
    AND children_records.ID = immunization_records.child_ID 
    AND immunization_records.First_Immunization_Date = CURDATE()"; 


$check = mysql_query($getnumbers); 
$found = mysql_num_rows($check); 
$details=mysql_fetch_assoc ($check); 
$date1=$details['First_Immunization_Date']; 
$todays_date = date("Y-m-d"); 
$today = strtotime($todays_date);  
$immunization_date1 = strtotime($date1); 

if($immunization_date1 == $today) 

for($counter=0;$counter<$found;$counter++) 
{ 
$date = $date1; 
$shots = "Polio and Diptheria";  

$cellphonenumber=$details['Cellphone_Number']; 
$childname=$details['Child_First_Name']; 
$parentname=$details['First_Name']; 
$msg="Dear $parentname, your child $childname is due for $shots shots on $date which is today. Message sent by Maisha Reminder System"; 
$encmsg=urlencode($msg); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,"http://localhost:13013/cgi-bin/sendsms?username=Maisha&password=m123456&to=$cellphonenumber&text=$encmsg"); 
curl_exec ($ch); 
curl_close ($ch); 
} 
} 

我已經做到了我是在同一個頁面上面的代碼重複四次對每個可能的免疫方式查詢。但是PHP不執行整個語句。它只會停止第一個堆棧。例如,使用上面的示例代碼,它只執行這一位,並留下與上述代碼完全相同的其他代碼並進行相關更改

有沒有一種方法可以確保PHP執行所有給定的語句。如果條件滿足,FOR循環或IF語句是否阻止執行所有語句?所有幫助讚賞。

+0

我假設一個監護人可能有多個免疫ID,並且你想確保你只發送一個包含所有可能的免疫ID的監護人的信息? – dmcnelis 2011-02-07 14:26:25

回答

0

假設一個監護人可以有多個ImmunizationIds,你要發送一個短信到一個特定的電話號碼,你可以採取的方法是這樣的:

$guardians = array(); 

while($row = mysql_fetch_array($yourResultSet)){ 
    if(isset($guardians[$row['Cellphone_Number']])){ //Make sure that your phone number has been initialized 
     $guardians[$row['Cellphone_Number']] .= "Text too add to message for this immunization"; 
    }else{ 
     $guardians[$row['Cellphone_Number']] = "Text too add to message for this immunization"; 
    } 
} 


foreach($guardians as $phoneNumber => $textMessage){ 
    sendMessage($phoneNumber, $textMessage); //where sendMessage is the function you use to send the text message 
} 

你也可以做到這一點的更多的OO方式,但這應該足以讓你開始。當然,你還需要確保該消息超過140個字符的結束了你在事件得到了你的理智檢查中「的sendMessage」,但不是這個問題的一部分。

+0

我會使用免疫ID的數組而不是僅追加字符串,然後在發送之前構建消息;然而,我猜這就是他的意思。 – redShadow 2011-02-07 15:01:11