-2
I set two Mysql widables to simplify one more Query that I want to deploy on my system. Using this command directly in SGBD, it works very well, however, when you want to use as a query string in my php script, it doesn’t work. Gives error in function mysqli_fetch_array(connected, queryString). What could be?
<?php
$str = " /*Defino as variáveis*/
SET @totVenda := (SELECT SUM(total) FROM tb_produto_item_estoque_saida);
SET @totPorcentagem := (SELECT SUM((ROUND((total/@totVenda*100),2))) FROM tb_produto_item_estoque_saida);
/*Query principal onde faço uso das variáveis*/
SELECT i.id, i.nome, SUM(ies.quantidade) AS quantidade, ies.valor, SUM(ies.total) AS total,
@totVenda AS TotalGeral,
SUM((ROUND((ies.total/@totVenda*100),2))) AS porcentagem
FROM tb_produto_item AS i
LEFT JOIN tb_produto_item_estoque_entrada AS iee ON i.id = iee.idItem
LEFT JOIN tb_produto_item_estoque_saida AS ies ON i.id = ies.idItem
GROUP BY i.id
ORDER BY porcentagem DESC";
$query = mysqli_query($conexao->conecta(),$str);
while($retorno = mysqli_fetch_array($query))
{
//Listaria o resultado aqui!
}
?>
Thank you from now on! Good week! :)
$query = mysqli_query($connected,$str); removes function connect()
– White
Fabio, why don’t you create a trial in your bank? This will improve the running time and make the application faster, with the process created, in PHP you will just need to call it and ready.
– Leonardo de lima silva
Call each line separately, variables persist in the session. By default you cannot multiquery with the
mysql_query
– Bacco