我有以下的JQuery/JavaScript的需要幫助做數學與PHP和JavaScript
<script>
var Quantity;
$("select").change(function() {
var str = "";
var price = <?php echo $row[price];?>;
$("select option:selected").each(function() {
str += $(this).text() + " ";
});
$(".plan_price").text("price : " + parseInt(str) * price + " baht");
Quantity = parseInt(str);
}).change();
</script>
這對於PHP/SQL
if ($row[item_amount] - 1 == 0) {
$sql = "update item set active='2',item_amount=item_amount-1,buy_time=NOW() where id='$id'";
} else {
$sql = "update item set item_amount=item_amount-1,buy_time=NOW() where id='$id'";
}
我想知道是否有什麼辦法,我從php中的$ row [item_amount]中減去/添加javascript變量Quantity的值,因爲我需要從數據庫中減去數量。
_note:你可以嵌入JavaScript到PHP,但你不能嵌入PHP內javascipt_ – 2013-04-08 06:55:38
@Kaii你是什麼意思? – vodich 2013-04-08 06:56:47
它只是意味着您可以將php變量值分配給javascript變量,但反之亦然。 – 2013-04-08 06:58:35