1
I have the following table:
DROP TABLE IF EXISTS `convenio`;
CREATE TABLE `convenio` (
`codigo` int(8) DEFAULT NULL,
`cpf` varchar(11) NOT NULL DEFAULT '0',
`Nome` varchar(35) DEFAULT NULL,
`valor` decimal(10,2) DEFAULT NULL,
`valorfinanc` decimal(10,2) DEFAULT NULL,
`dif` decimal(10,2) DEFAULT NULL,
`codger` varchar(6) DEFAULT NULL,
`cpf0` varchar(11) DEFAULT NULL,
`data` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`status` int(11) DEFAULT '0',
PRIMARY KEY (`cpf`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
What I need:
An update that makes:
UPDATE SET dif = valor - valorfinanc WHERE cpf = cpf
I’m trying this way:
$listaconv = mysql_query ("SELECT
*
FROM financeiro
ORDER BY nome",$convenio_conn)
or die (mysql_error());
while($row = mysql_fetch_array($listaconv)){
$VarConvCodigo = $row[0];
$VarConvCPF = $row[1];
$VarConvNome = $row[2];
$VarConvValor = $row[3];
$VarConvCodTotvs = $row[4];
$VarConvCPF0 = $row[5];
$VarConvData = $row[6];
$VarConvValorFinanc = $row[7];
$VarConvDifAvancFinanc = $row[8];
$VarConvStatus = $row[9];
$gera_divergencia = mysql_query ("UPDATE convenio
SET difavancfinanc = '$VarConvValor'-'$VarConvValorFinanc' WHERE cpf = '$VarConvCPF'",$convenio_conn)
or die (mysql_error());
}
Only you are not doing the calculation correctly and the values that appear in dif
has nothing to do with the bill, what I’m doing wrong ?
I really wasn’t going through correctness with var_dump($Row); I found the error, it was syntax error, thanks for the tip.
– Chefe Druida
Whenever I am going to deal with an array I use var_dump to check what I am dealing with... there is always a syntax error or even type incompatibility. Happy to be able to contribute!
– Igor