0
I have a table that has the column value, I query these values as follows
$sql2 = 'SELECT * FROM comisao_trabalho WHERE idJob="10" && pagoA="Dalton" ORDER BY id ASC';
$buscar = $conexao->prepare($sql2);
$buscar->execute();
$retorno = array();
$retorno['dados'] = '';
$retorno['qtd'] = $buscar->rowCount();
if($retorno['qtd'] > 0):
while($conteudo = $buscar->fetchObject()){
$retorno['dados'] = $conteudo->valor;
}
echo json_encode($retorno);
endif;
The values are in this format: U$ 2,500,00
You want the full amount?
– Tiago Boeing
Yes, the query returns me for example: 'U$ 2,500,00', 'U$ 750,00', U$ 1,000,00' . I need to add all the values that my while bring me
– dalton gonzalo Fuentes
I made an answer, if you have restrictions regarding the SQL query I ask you to inform, so I will edit the same. If this happens you will need to use a "counter" variable that receives itself and the value of the current line within WHILE.
– Tiago Boeing
I noticed another detail, that your column
valor
has the values saved in String format, it is not interesting that you save them this way, usually the currency symbol (in your case dollar, U$) is added via HTML or PHP when the data will be shown to the user. Use Double (Float) format to save values.– Tiago Boeing
The response of our friend Leandro Silva gives an overview of what would be the auxiliary variable (cont) I spoke.
– Tiago Boeing
Intendi, but similarly I would need to save the value without a dollar sign or I could use preg_replace in $content->value to leave only the numbers?
– dalton gonzalo Fuentes
If you use the form that our friend Leandro suggested, you can use the preg_replace() to leave only the value and you can already make the sum. Via SQL command the sum will only be returned if you save the values without a dollar sign.
– Tiago Boeing