没有在php文件中获取所有值的数据库

时间:2016-09-24 12:13:31

标签: php android

我正在创建一个PHP文件,用于使用POST方法在Android设备上发送推送通知。当我在HTML页面上插入数据时,会在PHP页面上显示数据,但我的PHP数组未获取所有行值。我该如何解决这个问题?

<?php
    require "init.php";
    $message = $_POST['message'];
    $title = $_POST['title'];
    $path_to_fcm='https://android.googleapis.com/gcm/send';
    $server_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    $sql = "select fcm_token from fcm_info";
    $result = mysqli_query($con,$sql);
    $row = mysqli_fetch_row($result);
    $key = $row[0]; 
    $headers = array('Authorization:key=' .$server_key,
            'Content_Type:application/json');
    $fields = array('to'=>$key,'notification'=>array('title'=>$title,'body'=>$message));
    $payload = json_encode($fields);
    $curl_session = curl_init();
    curl_setopt($curl_session,CURLOPT_URL,$path_to_fcm);
    curl_setopt($curl_session,CURLOPT_POST,true);
    curl_setopt($curl_session,CURLOPT_HTTPHEADER,$headers);
    curl_setopt($curl_session,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($curl_session,CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($curl_session,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
    curl_setopt($curl_session,CURLOPT_POSTFIELDS,$payload);
    $result = curl_exec($curl_session);
    curl_close($curl_session);
    mysqli_close($con);
?>

1 个答案:

答案 0 :(得分:1)

$key_array=array();
while ($row = mysqli_fetch_assoc($result)) {
  array_push($key_array,$row['fcm_token']);
}