1
I’m trying to make a simple query however, although Phpmyadmin perform the query, when I run the code Apache returns the message:
Notice: Undefined variable: rprd in D: xampp htdocs final views premorc.php on line 2723
My code is like this:
$data = date("d-m-Y");
$partes = explode("-", $data);
$ano = $partes[2];
$lj = $_GET['emp'];
$linha = $_GET['ans'];
$modal = $_GET['modal'];
$periodo = "$ano%";
$sql = "SELECT
sjy_vendas.tipo,
Sum(sjy_vendas.qt) AS qt,
Sum(sjy_vendas.qtv) AS qtv,
Sum(sjy_vendas.rprd) AS rprd,
Sum(sjy_vendas.rsrv) AS rsrv,
Sum(sjy_vendas.tprd) AS tprd,
Sum(sjy_vendas.tsrv) AS tsrv,
Sum(sjy_vendas.vlr_compra) AS vlr_compra
FROM sjy_vendas
WHERE sjy_vendas.empresa = $lj
AND sjy_vendas.tipo = $linha
AND sjy_vendas.dt_nf LIKE '$periodo'
GROUP BY sjy_vendas.tipo";
$resultado = $MySQLi->query($sql) OR trigger_error($MySQLi->error, E_USER_ERROR);
while ($dados = $resultado->fetch_object()) {
$qtv = $dados["qtv"];
$rprd = $dados["rprd"];
}
if($modal == "X"){
$anterior = $qtv;
} else if($modal = "F"){
$anterior = $rprd; // Essa é a linha 2723
}
Meaning that your query did not return anything (it did not enter while) or maybe that if/Else should be inside while.
– rray
You are searching for an object, and accessing with an array, you will not search even, ve change where is "$data['qtv']" for "$data->qtv" no longer solves
– AnthraxisBR
Rray, thank you for the answer. To define the variable I only need the code that is already described.
– Webster Moitinho
Anthraxisbr thanks for the answer, but it is giving the same error. I have tried with fetch_array and gives the same error. This code is working on another page (with another query of course), but here is giving error.
– Webster Moitinho
Put $data = $result->fetch_object() out of while, and place var_dump($data), to see if the query is being made
– AnthraxisBR
Thanks @Anthraxisbr, that’s right. I was setting an object with an array. Now it’s working. Thanks.
– Webster Moitinho
But when I copied and pasted from the test page to production page continued giving the same error. :/
– Webster Moitinho