用PHP计算web服务中的selectdistinct

用PHP计算web服务中的selectdistinct,php,json,rest,Php,Json,Rest,我在选择和计算数据时遇到问题。我在RESTfulWeb服务服务器端。我的服务是这样的: private function grafik() { if($this->get_request_method() !="GET") { $this->response('',406); } $sql = "

我在选择和计算数据时遇到问题。我在RESTfulWeb服务服务器端。我的服务是这样的:

private function grafik()
        {
            if($this->get_request_method() !="GET") 
                {
                    $this->response('',406);
                }
                    $sql   = "select distinct operating_system from data";
                    $query = $this->mysqli->query($sql) or die($this->mysqli->error.__LINE__);
                    //$query = mysql_query( $sql )  or die(mysql_error());
                    while( $ret = $query->fetch_array() ){

                    $os=$ret['operating_system'];

                    $sql_jumlah   = "SELECT * FROM data WHERE operating_system='$os'";  
                    $query_jumlah = $this->mysqli->query($sql_jumlah) or die($this->mysqli->error.__LINE__);

                         $data = mysqli_num_rows( $query_jumlah );
                            $jumlah = $mydata;
echo $jumlah;   
echo $os;
问题是,我真的很困惑如何才能将不同变量上的
$jumlah
$os
导入客户端

$json = file_get_contents('http://localhost/proejct/services/server');

当我
echo$json
时,我在
$json
上得到
$jumlah
$os
,但我想在两个不同的变量中得到它们。我该怎么办?

发现注射漏洞(再次)原谅??抱歉,如果我犯了错误,谷歌注入攻击,并准备了声明。底线:如果
$os
的值包含一个单引号,或在末尾包含一个反斜杠,则二次查询将失败,或可能导致数据损坏。使用名为
DOS'的操作系统;删除表数据;--,您将丢失所有数据。PS:方法不应该回音,它们应该
返回
数据,让用户(调用该方法的人)决定数据下一步的去向(回音,或写入日志,或其他)是的,你说得对,elias,我是新的一个….,我明白了:(不用担心,我们在学习时都犯过错误……如果我显得傲慢或敌意,我很抱歉。