PHP不执行所有给定语句

PHP不执行所有给定语句,php,mysql,Php,Mysql,正如本帖的大多数读者所知,我在使用for-loop和if语句发送批量短信时遇到了问题。然而,我已将我的问题简化为以下内容。我只使用AND,并对每个免疫日期重复查询 $getnumbers="SELECT guardian_records.First_Name, guardian_records.ID, guardian_records.Cellphone_Number, children_records.Child_First_Name, chi

正如本帖的大多数读者所知,我在使用for-loop和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);
} 
}
$getnumbers=“选择
监护人的名字,
guardian_records.ID,
guardian_records.手机号码,
children_records.children_名字,
儿童档案。监护人身份证,
儿童(u records.ID),,
免疫接种记录。儿童ID,
免疫记录。首次免疫日期,
从…起
卫报(u)记录,,
儿童(u)档案,,
免疫接种记录
哪里
监护人_records.ID=儿童_records.guardian_ID
和children_records.ID=免疫接种_records.children_ID
和免疫记录。第一次免疫日期=CURDATE();
$check=mysql\u查询($getnumbers);
$found=mysql\u num\u行($check);
$details=mysql\u fetch\u assoc($check);
$date1=$details[“首次免疫接种日期”];
$todays_date=日期(“Y-m-d”);
$today=标准时间($todays\u date);
$date1=标准时间($date1);
如果($date1==$today)

对于($counter=0;$counter假设一个监护人可以有多个免疫ID,并且您希望向特定的电话号码发送一条短信,您可以采取如下方法:

$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
}

你也可以用一种更加面向对象的方式来做这件事,但这应该足以让你开始。当然,如果消息长度超过140个字符,你还需要确保在“sendMessage”中进行了理智检查,但这不是问题的一部分。

我假设一个监护人可能有多个免疫ids、 你想确保每个监护人只发送一条包含所有可能的免疫ID的消息吗?我会使用免疫ID数组,而不仅仅是附加字符串,然后在发送之前构建消息;然而,我猜这就是他的意思。总的来说,我同意,redShadow。我只是想让它像po一样简单可能。我最终使用了一个带有数组的for循环。但是我得到了一个特殊的错误。第一条短信是正确的,但是其余的短信使用了我表中的第一个孩子和数据库中的所有快照,因为日期,我想如果你在select语句中添加一个DISTINCT,会怎么样?看起来,因为你使用了OR,你可能最终得到与cou相同的结果不同时间的ple。这可能会导致您遇到的问题。但是使用DISTINCT,则每个记录将只处理一次。