2011-02-07 4 views
1

このスレッドでは、ほとんどの人が知っているように、forループとifステートメントを使用してバルクSMSを送信する際に問題がありました。しかし、私は以下のように質問を減らしました。私は、私はそれを行っている方法は、私は同じページで上記のコードは、各可能な免疫化のために4回繰り返されているある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

1人の保護者が複数の予防接種IDを持っている可能性があります。あなたは、すべての予防接種IDを含む保護者1人のメッセージしか送信しないようにしたいと思いますか? – dmcnelis

答えて

0

1ガーディアンは、複数の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

+0

一般に、私は同意する、redShadow。できるだけシンプルにしようとしていました。 – dmcnelis

+0

私は結局、forループを配列に使ってしまった。しかし、私は異常な異常を取得します。最初のSMSは正しいですが、残りの部分は私のテーブルの最初の子供とデータベース内のすべてのショットを私が考える日付のために使用します – MaxI

関連する問題