2011-02-07 9 views
1

이 스레드에서 다음에 나오는 대부분의 사람들이 알고 있듯이 for 루프와 if 문을 사용하여 대량 SMS를 보내는 데 문제가있었습니다. 그러나 나는 나의 쿼리를 다음과 같이 줄였다. 난 단지 사용과 그리고 각 예방 접종 날짜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

답변

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

+0

일반적으로 나는 동의한다, redShadow. 가능한 한 간단하게 유지하려고했습니다. – dmcnelis

+0

배열에 대해 for 루프를 사용하여 종료했습니다. 하지만 나는 이상한 결과를 낳습니다. 첫 번째 SMS는 정확하지만 나머지는 내가 생각하는 날짜 때문에 데이터베이스의 모든 테이블과 테이블에있는 첫 번째 아이를 사용합니다. – MaxI

관련 문제