2016-06-25 2 views
0

다음 메시지를 보내려면 mysql 데이터베이스를 쿼리하는 다음 PHP 스크립트가 있습니다. 나는 "메시지"변수를 데이터베이스 테이블의 1000 행마다 루프에 보내고 싶다. 아래 코드는, 누군가가 오류를 찾을 수 있습니까? PHP 스크립트 자체는 오류를 생성하지 않지만 1000 행마다 메시지를 보내지 않습니다. 대신 데이터베이스 테이블의 모든 행에서 완전히 실행되어 GCM에서 메시징 오류가 발생합니다.PHP가 SQL 사용자를 통해 올바르게 반복되지 않습니다

<?php 
session_start(); 
include_once 'connect.php'; 

    function send_notification($con,$registatoin_ids, $message) { 
    $url = 'https://android.googleapis.com/gcm/send'; 

    // prep the bundle 
    $msg = array 
    (
'message' => "message", 
'title'  => 'title', 
'subtitle' => 'subtitle. subtitle', 
'msgcnt' => 3, 
'vibrate' => 1, 
'sound'  => 'default', 
'soundname' => 'beep.wav', 
'largeIcon' => 'large_icon', 
'smallIcon' => 'small_icon' 
); 
    $fields = array 
    (
'registration_ids' => $registatoin_ids, 
'data'   => $msg 
    ); 


    $headers = array(
     'Authorization: key=' . apiKey, 
     'Content-Type: application/json' 
    ); 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); 
    $result = curl_exec($ch); 
    if ($result === FALSE) { 
     die('Curl failed: ' . curl_error($ch)); 
    } 
    curl_close($ch); 
    echo $result; 

} 

    if(isset($_SESSION['login_user'])){ 
    if(isset($_POST["submit"]) && isset($_POST["message"])) {  
    $num=$con->query("SELECT gcm_regid from gcm_users")->rowCount(); 
    $current_num=0; 
    $message=$_POST["message"]; 
    for($i=0;$i<$num/999;$i++){ 

    $query=$con->query("SELECT gcm_regid from gcm_users LIMIT   
    $current_num,999"); 

foreach($query as $data) { 
$row[]=$data["gcm_regid"]; 
} 

    $pushStatus = send_notification($con,$row, $message); 
    $current_num+=999; 
    } 
    }else if(isset($_POST["logout"])){ 

    if(session_destroy()) // Destroying All Sessions 
{ 
header("Location: login.php"); // Redirecting To Home Page 
} 
} 

?> 

답변

0

$row[] 항상 $ 행이 삭제되지 않습니다.

$row[]=array(); // clear array 
foreach($query as $data) { 
$row[]=$data["gcm_regid"]; 
} 
+0

대답을위한 Thnx, 시도했지만 스크립트는 여전히 모든 행을 한 번에 보냅니다. GCM이 메시지를 반환합니다. 대량 메일 (1784)의 수가 최대 허용 한도 (1000)를 초과하므로 메일이 한 번에 테이블의 모든 행으로 전송된다고 추측 할 수 있습니다. – qwertyg

관련 문제