How to return json_encode?

0

I need to return a select done in PHP. It is working normally, but at the time of displaying the result it returns me an error at the end. I need to return json_encode to the android recognize. Follow the schedule below

mysql_connect('maquina','aa','senha');
mysql_select_db('aaaa') or die (mysql_error());



$Cod_Empresa = $_GET['aaaa'];
$UC = $_GET['sss'];
$di = $_GET['dddd'];
$df = $_GET['ssdddd'];
$tensao  = strtoupper($_GET['eeeeeeeeeeeee']);

if (($di != "") && ($df != ""))
    {
        $periodo = '
        && D.Mes_Ref >= "'.$di.'"
        && D.Mes_Ref <= "'.$df.'"
            Order By Mes_Ref DESC
                ';
    }
else
    {
        $periodo = '
            Order By Mes_Ref DESC
            Limit 0,12
                ';
    }
switch($tensao)
    {
        case 'BT':
            $tensao_ = "";
            break;
        case 'AT':
            $tensao_ = "
                && D.Tip_Fatur = 0
                && D.Classe in ('A1','A2','A3','A3a')
            ";
            break;
        case 'MT':
            $tensao_ = "
                && D.Tip_Fatur = 0
                && D.Classe in ('A4','As')
            ";
            break;
        case 'ML':
            $tensao_ = "
                && D.Tip_Fatur = 1
            ";
            break;
    }



switch($tensao)
{
    case 'BT':
        $sql = "SELECT Mes_Ref, round(Total_Fatura,2) as Valor_em_Reais                                                 
                FROM Tab_Fatura_BT D
                    WHERE Cod_Empresa = ".$Cod_Empresa."
                    && Cod_UC = ".$UC."                     
                            ".$periodo."    
                                            ";
                                        break;
    default:
        $sql = "SELECT  D.Mes_Ref,round(V.Valor_Total_cor,2) as Valor_em_Reais                                  
                FROM Tab_Fatura_Dados D, Tab_Fatura_Valores V, Tab_Fatura_Leituras L
                    WHERE D.Cod_Empresa = ".$Cod_Empresa."
                    && D.Cod_UC = ".$UC."
                    && V.Cod_Empresa = D.Cod_Empresa
                    && V.Cod_UC = D.Cod_UC
                    && V.Cod_Fatura = D.Cod_Fatura
                    && L.Cod_Empresa = D.Cod_Empresa
                    && L.Cod_UC = D.Cod_UC
                    && L.Cod_Fatura = D.Cod_Fatura
                        ".$tensao_."
                            ".$periodo." 
                                            ";
                                        break;
}

            $query = mysql_query( $sql ) or die('Could not query');     

        for($rows = array(); $row = mysql_fetch_array($query); $rows[] = $row);
                {   

                    linha 99 $rows[] = $row->Mes_Ref;
                    linha 100 $rows[] = number_format($row->Valor_em_Reais,2,'.',',');
                    echo json_encode($rows);
                } 

?>

This returns me the following error:

    
asked by anonymous 03.05.2016 / 13:58

1 answer

0

The error can be in your php, check there in the code if the name, password and address of the bd. take a look if you are right td ... in this site www.hostinger.com you can upload your php and do your tests in real domain and free. with me gave the same error and the problem was the name of a table in php code ...

    
03.05.2016 / 14:47