I am fetching prices from my database by article_no. I am sending the article via ajax to php:
var comps_gehaz = {};
comps_gehaz['articleNumbers'] = 38292783;
$.ajax({
type: "POST",
url: "php/gehaz.php",
data: {gehaz_json_data: JSON.stringify(comps_gehaz)},
dataType: "text",
success: function (msg, string, jpXHR) {
if(msg) {
$('#gehaz_priceTag').html(msg);
} else {
console.log('Something else went wrong.');
}
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "
Error:" + err);
}
});
My table structure in MySQL is:
... "price" -> decimal(10,2) "articleNo" -> BIGINT ...
PHP:
$gehaz_json_data = $_POST['gehaz_json_data'];
$obj = json_decode($gehaz_json_data, true);
$articleNumber = $obj['articleNumber'];
$getMoney = "SELECT price FROM Articles WHERE articleNo = '$articleNumber'";
if (mysqli_query($db_link, $getMoney)) {
$result_price = mysqli_query($db_link, $getMoney);
while ($row = mysqli_fetch_array($result_price)) {
$list_price_notFormat = $row['price'];
}
echo $list_price_notFormat;
}
If the price value is 345.56, it displays it correct. But if it is a bigger than thousand like 3036.47, it only echo the first digit '3'.
I think I know what the problem was.
the values in my database are set automatically with javascript/node.js. I am reading the values from a Excel file and save them in my MySQL-table. before putting them in the column with datatype 'Decimal 10,2', I had to parse the value from my Excel-Sheet for example '1.253,64' to String so I can replace the '.' by '' end ',' by '.', so it looks like 1253.64
I assume that is the reason why it only reads the first digit.
Should I change the datatype from decimal to float or is there a better way for saving prices in mysql?
Figure out how to export the number, not the string from Excel. You are stumbling over "locale" issues with "thousands separator".