I do not know how to do it or who to turn to. I need to do this json return with Jquery.Ajax
I would like to pass parameters more or less like this
In JAVASCRIPT I have this
$.ajax({
type: "POST",
url: "../execs/proc_fluxocaixa.php",
data: {d_acao: "grafico", c_tipo: tipo, c_dia: dia},
dataType: "json",
success: function(ret_dados){
var pageviews ret_dados["r_dados"];
}
});
My PHP looks like this:
if($acao == "grafico"){
$tipo = $_POST["tipo"];
$dias = 30;
$mes = 3;
if ($tipo == 0){
///Debito
$Saida[] = array();
for($i=1; $i <= $dias; $i++) {
$dataC = date("Y-$mes-$i");
$diaSQL = $Sv->selectDB("SELECT SUM(valor) TotalDia FROM mov_contas WHERE tipo = 'D' AND apagado = 0 AND banco = 0 AND data >= '$dataC 00:00:00' AND data <= '$dataC 23:59:59' GROUP BY data");
if (count($diaSQL) == 0){
$TotalValDia = 0;
} else {
$TotalValDia = $diaSQL[0]["TotalDia"];
}
$Saida[] = $i . "," . $TotalValDia;
}
}
$retorno["r_dados"] = $Saida;
}
How do I in PHP and return to look like this:
var pageviews = [
[1, randValue()],
[2, randValue()],
[3, 2 + randValue()],
[4, 3 + randValue()],
[5, 5 + randValue()],
[6, 10 + randValue()],
[7, 15 + randValue()],
[8, 20 + randValue()],
[9, 25 + randValue()],
[10, 30 + randValue()],
[11, 35 + randValue()],
[12, 25 + randValue()],
[13, 15 + randValue()],
[14, 20 + randValue()],
[15, 45 + randValue()],
[16, 50 + randValue()],
[17, 65 + randValue()],
[18, 70 + randValue()],
[19, 85 + randValue()],
[20, 80 + randValue()],
[21, 75 + randValue()],
[22, 80 + randValue()],
[23, 75 + randValue()],
[24, 70 + randValue()],
[25, 65 + randValue()],
[26, 75 + randValue()],
[27, 80 + randValue()],
[28, 85 + randValue()],
[29, 90 + randValue()],
[30, 95 + randValue()]
];