First hit query, remove single quotes from column valor
, define an alias for the calculated field so it is more readable to retrieve the values in php, if no nickname is specified, php will assume that 'name' is the expression used, in case sum(valor)
or 0(zero) if used mysqli_fetch_array()
$consultar = "SELECT SUM('valor') FROM vendascalc WHERE valor";
Change to:
$consultar = "SELECT SUM(valor) as total FROM vendascalc WHERE valor";
After the mysqli_query()
recover the value of the consultation with mysqli_fetch_assoc()
and make a loop to get all rows returned by query.
$resulta = mysqli_query($mysqli, $consultar);
while($item = mysqli_fetch_assoc($resulta)){
echo $item['total'] .'<br>';
}
There is no mistake?
– Maniero
$query = "SELECT SUM('value') FROM vendascalc WHERE value"; ...value what?
– Israel Zebulon
http://php.net/manual/en/mysqli-result.fetch-row.php
– bfavaretto