0
I need to return a select made in PHP. It is working normally, but when displaying the result it returns me an error at the end. I need to return one json_encode
to the android recognize. Follow the programming 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:
Hello, Try doing "echo json_encode($Rows);" after for
– Tiago Gomes
Returned me the same mistake!
– Tiago
Which is line 99 and 100 ?
– Diego Souza
Are these two $Rows[] = $Row->Mes_ref; $Rows[] = number_format($Row->Valued,'.',',');
– Tiago
if I just display json_encode without lines 99 and 100 it returns me correctly.. but however I need to treat these lines to resume a more presentable value... but with these two lines ai generates me an error presented above..
– Tiago
change $Row->Mes_ref to $Row[Mes_ref] and $Row[Valued].
– Tiago Gomes