![](/img/trans.png)
[英]Use selected cell value from table to select a cell in another table with the same value
[英]Take value from form input, multiply it by MySQL table cell value and write result to another cell in same table
請原諒我的無知,我仍然是一個初學者,我什至不知道這是否可能。
我需要在數據庫中插入一種基於另一種貨幣的價格表(基於EUR,以美元輸出)。
我的表格可以接受轉換乘數值的輸入,並將值放入數組中應該相對簡單(即使對我來說!)
<?php
// Make a MySQL Connection
$query = "SELECT price FROM table";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row[euros].
//here is where I need to perform the calculation with the result going into $row[dollars](euros * ex.rate = dollars)
UPDATE table SET dollars=INT($row[dollars]);
}
?>
不幸的是,我無法解決這個問題。
我不知道如何將表單輸入與每個歐元值相乘並將結果以整數形式寫入相應的Dollars單元中。
我要做的是為此編寫一個SQL查詢:
UPDATE `table` SET dollars=euros*1.23 WHERE 1
您當然可以在PHP中執行此操作:
<?php
// first, prevent anyone from tampering with the query!
$factor = floatval($user_input);
// then the query itself
$result = mysql_query("UPDATE `table` SET dollars=euros*{$factor} WHERE 1");
?>
在撰寫本文時,在使用關聯數組時,應使用單引號,例如不是$ row [dollars]而是$ row ['dollars']。 將這些里面的冰壺包起來:
echo "dollars: {$row['dollars']}";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.