1
I want to save the value of a select to a php variable, and then show it in html.
I tried something like:
function totalEspumas(){
$banco = abrirBanco();
$quantidade_pedidos = "SELECT SUM(quantidade) from pedidos";
$resultado = $banco->query($quantidade_pedidos);
$banco->close();
$pedidos = '';
while($row = mysqli_fetch_array($resultado)){
$pedidos[] = $row;
}
return $pedidos;
}
The result of the query is 23. Html:
<?php
$totalespuma = totalEspumas();
?>
<?php echo $totalespuma ?>
When I try to show the variable value, I get:
Catchable fatal error: Object of class mysqli_result could not be converted to string
You must be trying to give an echo totalEspumas();, it returns an array, it cannot be done like this
– Woton Sampaio