I have a select, inside it I have a function:
SELECT VAL1, VAL2, ".funcao('VAL1', 'VAL2')." AS soma FROM Conta WHERE soma < 100
Table structure CONTA
--------------------
| ID | VAL1 | VAL2 |
--------------------
| 1 | 10 | 50 |
--------------------
| 2 | 50 | 80 |
--------------------
| 3 | 30 | 70 |
--------------------
If I use the following structure in the function:
function funcao($valor1, $valor2)
{
$retorno = $valor1 + $valor2;
return $retorno;
};
I can return the value of each column in a good one, and I still get the result!
Dai I tried to work the function more and apply the value inside a string. Ex:
function funcao($valor1, $valor2)
{
$res = "Os números a ser somados são ".$valor1." e ".$valor2."";
echo $res ;
//Esse echo serve apenas de exemplo, pra mostrar o retorno da variável
};
Only this I can not do! When I applied the variable $valor1
or $valor2
, instead of showing the value referring to the column, it showed the column name itself, that is, VAL1
and VAL2
My question is
Is it possible to work with these variables in a more complex function according to the example above, without losing the value of the column? Since when I try to do this the value stays as "VAL1" instead of 10 or 50.
In simpler way! Even if I simply want to make an "echo $ value1" within the function, the result is "VAL1" instead of "10"