Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从MySQL数据库获取记录时显示null的php_Php_Mysql_Push Notification_Google Cloud Messaging - Fatal编程技术网

从MySQL数据库获取记录时显示null的php

从MySQL数据库获取记录时显示null的php,php,mysql,push-notification,google-cloud-messaging,Php,Mysql,Push Notification,Google Cloud Messaging,我正在尝试使用php类使用GCM将数据发送到appphonegap。 在这里,数据存储到数据库中,并使用PHPGCM类发送。 问题在于,当发送所有列时,它会显示空值 <?php class GCMPushMessage { var $url = 'https://android.googleapis.com/gcm/send'; var $serverApiKey = "xxxxxxx"; var $devices = 0; function setDev

我正在尝试使用php类使用GCM将数据发送到appphonegap。 在这里,数据存储到数据库中,并使用PHPGCM类发送。 问题在于,当发送所有列时,它会显示空值

<?php
class GCMPushMessage {
    var $url = 'https://android.googleapis.com/gcm/send';
    var $serverApiKey = "xxxxxxx";
    var $devices = 0;

    function setDevices($deviceIds)
    {

        if(is_array($deviceIds)){
            $this->devices = $deviceIds;
        } else {
            $this->devices = array($deviceIds);
        }
    }
    function send($message, $data = false)
       {
        if(!is_array($this->devices) || count($this->devices) == 0){
            $this->error("No devices set");
        }

        if(strlen($this->serverApiKey) < 8){
            $this->error("Server API Key not set");
        }

        $fields = array(
            'registration_ids'  => $this->devices,
            'data'              => array( "message" => $message ),
        );

        if(is_array($data)){
            foreach ($data as $key => $value) {
                $fields['data'][$key] = $value;
        }
        }
        $headers = array( 
            'Authorization: key=' . $this->serverApiKey,
            'Content-Type: application/json'
        );
        // Open connection
        $ch = curl_init();

        // Set the url, number of POST vars, POST data
        curl_setopt( $ch, CURLOPT_URL, $this->url );

        curl_setopt( $ch, CURLOPT_POST, true );
        curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

        curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );

        // Avoids problem with https certificate
        curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);

        // Execute post
        $result = curl_exec($ch);

        // Close connection
        curl_close($ch);

        return $result;
    }

}
    $id=$_POST['id'];
    $diagnosis=$_POST['diagnosis'];
    $instructions=$_POST['instructions'];
    $doc_name=$_POST['doc_name'];
    $med_id=time().rand(11,99).time();
    $str="insert into prescription values('$id','$diagnosis','$instructions','$doc_name','$med_id')";
    $res=@mysql_query($str)or die(mysql_error());
    $nf=$_POST['nf'];
    $i=1;
    while($i<=$nf)
        {
        $medicine=' ';
        $tm1=$tm2=$tm3=0;
        $medicine=$_POST['medicine_'.$i];
        $tm='';
        if(isset($_POST['tm_1_'.$i]))
            {$tm1=1;}
        if(isset($_POST['tm_2_'.$i]))
            {$tm2=1;}
        if(isset($_POST['tm_3_'.$i]))
            {$tm3=1;}
        $dosage=$_POST['dosage_'.$i];
        $str="insert into medicine values('$med_id','$dosage','$medicine','$tm1','$tm2','$tm3')";
        $res=@mysql_query($str)or die(mysql_error());
        $i++;
        }
        $id = $_POST['id']; 
        $gcpm = new GCMPushMessage();
$sql=mysql_query("select token from device where id=".$id);
$rs=mysql_fetch_assoc($sql);
$gcpm->setDevices($rs['token']);
$query1=mysql_query("select * from medicine,prescription where med_id=mid and id=".$id);
while($rs1=mysql_fetch_assoc($query1))
{
$rows[]['medicine_name']=$rs['medicine_name'];
$rows[]['tm_1']=$rs['tm_1'];
$rows[]['tm_2']=$rs['tm_2'];
$rows[]['tm_3']=$rs['tm_3'];
$rows[]['dosage']=$rs['dosage'];
}
$rows[]['diagnosis']=$rs['diagnosis'];
$rows[]['instructions']=$rs['instructions'];
print_r($rows);
$response = $gcpm->send($message, $rows);
?>

当我试图显示$行时,它显示所有项目的空值。但是数据正在被插入数据库。很抱歉发布了全部代码。我是个新手。请提供帮助。

由于您尚未发布日志,因此很难找出问题的根本原因。错误的确切原因可能是空值,但它发生在哪一行将更有助于诊断问题

我想让您看看这个处理从两个表中插入和提取多行的方法

关于GCM的实施,请看一下这个。并确保结构是模块化的,如示例中所述

希望有帮助