I have a SQL database that includes a column called TotaleFattura
where I store the total amount of an invoice, in the format "xxx,xx" (so with comma, in italy this is the separator for decimals)
In the php script I try to take this value and if it's bigger than 77,47 I have to display a string via echo command. If it's smaller, nothing has to happen and the string must be empty.
Issue is that the operation not works! I means that the condition is always FALSE also when it shoudl be TRUE (and in some cases it is always TRUE also when it should be FALSE, please keep reading you will understand).
So happens that also when the db field is bigger than 77,47 the strings not shows. Basically it seems that the "if" statement is unable to compare correctly the two parameters/variable like they are a string and a number that cannot be compared, but from what I know PHP will manage the conversion itself. Or I miss something?
Anyway, this is my code
$totfattura = $row['TotaleFattura'];
echo "Totale Fattura: " . $totfattura . "<br />";
if ($totfattura > "77,47") {
$notefattura = "this is my note. invoice is bigger than 77,47";
}
echo "Note Fattura: " . $notefattura . "<br />";
I made the SQL table using the "import" from a CSV file directly in the PhpMyAdmin panel from my hosting provider.
I tried to have the import of the data in two different ways:
decimal(5,2)
or varchar(8) utf8_general_ci
but nothing changed about the result.
So basically, to have a recap:
If I use
$totfattura > "77,47"
the result is ALWAYS TRUE (also when $totfattura is smaller than 77,47)
Then, If I use
$totfattura > "77.47"
the result is ALWAYS FALSE (also when $totfattura is bigger than 77,47)
I'm sure I'm missing something really simple, but can't figure it out. Hope someone will help me. Thanks!
p.s. If you need any other data or a db extraction please ask and I will provide you all the details.