正如大多数人都知道的那样,我在使用for循环和if语句发送批量短信时遇到了问题。但是我已将查询减少到以下内容。我只使用AND并重复每个免疫日期的查询
$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 :(得分:0)
假设一个Guardian可以拥有多个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”中进行完整性检查,但这不是此问题的一部分。