【发布时间】:2017-07-20 13:44:49
【问题描述】:
我正在通过 article_no 从我的数据库中获取价格。我正在通过 ajax 将文章发送到 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 + "\nError:" + err);
}
});
我在 MySQL 中的表结构是:
... “价格”-> 小数(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;
}
如果价格值为 345.56,则显示正确。但如果它是大于千的,比如 3036.47,它只会回显第一个数字“3”。
【问题讨论】:
-
$list_price_notFormat = (float)$row['price'];或$list_price_notFormat = (double)$row['price']; -
你能在这里添加一些db的值吗?是文章否是 P.K. ?
-
@Anant 没用
-
@kamal...价格的价值是例如234.56 或 3736.43
-
好的,但我在问 articleNo 是 PK 吗? 因为如果不是,那么由于 db 中该 articleNo 的最后一个值(如 3),您可能只会得到 3
标签: php jquery mysql ajax decimal