Php 如何将从mysql数据库检索到的下拉框值相乘(或求和)

Php 如何将从mysql数据库检索到的下拉框值相乘(或求和),php,html,Php,Html,我被困在下拉框值计算上。有人能帮我解决这个问题吗 我的网页上有两个下拉框,下拉框中的值是从mysql数据库中检索的 下拉框A显示两个不同的值,即Chassise\u Name和Chassise\u price,下拉框B显示项目的数量 Dropdown box "A" Dropdown box "B" SuperServer 7036A-T(Black) $90 3 Superserver 7036A-

我被困在下拉框值计算上。有人能帮我解决这个问题吗

我的网页上有两个下拉框,下拉框中的值是从mysql数据库中检索的

下拉框
A
显示两个不同的值,即
Chassise\u Name
Chassise\u price
,下拉框
B
显示项目的数量

    Dropdown box "A"                      Dropdown box "B"
SuperServer 7036A-T(Black)    $90                    3
Superserver 7036A-T(黑色)
机箱名称中检索
底盘价格中检索$90

3
从其他表中的数量中检索

问题:
我怎样才能只取下拉框
A
中的价格乘以下拉框
B
中的数字

这是我的密码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head><title></title></head>
<body>
<form action="test2.php" method="post">
<?php
mysql_connect("host", "users", "pass") or die(mysql_error());
mysql_select_db("a4202648_wang") or die(mysql_error());

echo "<table border='1'>";
echo "<tr><td>";

$result = mysql_query("SELECT Chassis_Name, Chassis_Price FROM Chassis where Chassis_Form_Factor='ATX'") 
or die(mysql_error());  
echo '<select name="Chassis" onChange="change()">'; 
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row into a table
    echo '<option Name="Chassis">',$row['Chassis_Name'],' &nbsp;&nbsp;&nbsp;',$row['Chassis_Price'],'&nbsp;','</option>'; 
} 
echo '</select>';
echo "</td>";
echo "<td>";

$result= mysql_query("SELECT Number FROM Quantity") 
or die(mysql_error());  
echo '<select name="Quantity" Value="Quantity" onChange="change()" >'; 

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result)) {
      // Print out the contents of each row into a table
      echo '<option Name="Quantity">',$row['Number'],'</option>'; 
} 
echo '</select>';
echo "</td></tr>";
echo "</table>";
?>
<input type="submit" />
</form>
</body>
</html>

为了可读性,我将代码减少了一点,但您需要添加id=“chassis”和id=“quantity”,以便在求和时可以引用该dom对象。 确保将
放在文档的开头

<script type="text/javascript">
    $('document').ready( function() {
        function change() {
            var quantity = $('#quantity').val();
            var chassis = $('#chassis').val();
            var sum = quantity * chassis;
            $('#the_sum').val(sum);
        }
    });
</script>
<form action="test2.php" method="post">
<?php
  echo '<select id="chassis" name="Chassis" onChange="change()">'; 

  echo '<option value="{$row['Chassis_Name']}">{$row['Chassis_Name']}&nbsp;&nbsp;&nbsp;{$row['Chassis_Price']}&nbsp;</option>'; 

  echo '<select id="quantity" name="Quantity" Value="Quantity" onChange="change()" >';
  echo '<option value="{$row['Number']}">{$row['Number']}</option>';

?>
<input type="text" value="" id="the_sum" />
<input type="submit" />
</form>
</body>
</html>

$('document').ready(函数(){
函数更改(){
变量数量=$(“#数量”).val();
var chassis=$('#chassis').val();
var总和=数量*底盘;
$('u sum').val(sum);
}
});

如何将a和b的值相乘?这是在选择了每个之后吗?