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 does:
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());
}
But you are not doing the calculation properly and the values that appear in dif
have nothing to do with the account, what am I doing wrong?