更改PHP和JavaScript中的小计值

时间:2012-01-19 13:18:20

标签: php javascript arrays payment

到目前为止,我有以下代码,我想计算我的小计以获得总付款。有人可以帮忙吗?

$viewx = mysql_query("select distinct toorderid from ordercontainer where toordercategory='$ordercategory' and customerid=$customerid") or die("Could not execute the select query." .mysql_error());
while($rowx = mysql_fetch_array($viewx))
{
    $id = $rowx['toorderid'];

    $view = mysql_query("select * from products where menuid = '$id' and status = 'Active'") or die("Could not execute the select query" .mysql_error());
    while($row = mysql_fetch_array($view))
    {
        $item = $row['item'];
        $details = $row['details'];
        $price = $row['price'];

        echo '<tr><td>'.$item;
        echo '<div style="margin:0px 0px 0px 5px">'.$details.'</div></td>';
        echo '<td><select name="qty" onChange="" style="width:50px"><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select></td>';
        echo '<td align="center">'.$price.'</td>';
        $qty = ;
        $totalprice = ;
        $subtotal = ($totalprice * $qty);
        $totalpayment = $subtotal; 
        echo '<td align="center">'.$subtotal.' Php</td></tr>';
    }
}

1 个答案:

答案 0 :(得分:0)

首先......你在PHP中打印一个选择框...这不是问题,问题是PHP期望选择框的值作为回报来计算总价。更好的解决方案是让PHP按原样编写所有内容,但计算部分除外...然后让JAvascript在选择框的onchange事件中计算总价。然后让jquery将结果附加到小计区域。

祝你好运。