Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改PHP和JavaScript中小计的值_Php_Javascript_Arrays_Payment - Fatal编程技术网

更改PHP和JavaScript中小计的值

更改PHP和JavaScript中小计的值,php,javascript,arrays,payment,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 = mys

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

$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>';
    }
}
$viewx=mysql\u查询(“从ordercontainer中选择不同的toorderid,其中toordercategory='$ordercategory'和customerid=$customerid”)或die(“无法执行选择查询。”.mysql\u error());
while($rowx=mysql\u fetch\u数组($viewx))
{
$id=$rowx['toorderid'];
$view=mysql\u查询(“从产品中选择*,其中menuid='$id'和status='Active'))或die(“无法执行选择查询”。mysql\u error());
while($row=mysql\u fetch\u数组($view))
{
$item=$row['item'];
$details=$row['details'];
$price=$row['price'];
回显“”。$项;
回显“.$details.”;
回音‘12345678910’;
回声“.$price.”;
$qty=;
$totalprice=;
$小计=($总价*$数量);
$totalpayment=$subtotal;
回显“”。$小计。'Php';
}
}

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


祝你好运。

你能准确地解释一下你的错误吗?当你阅读这些代码时,里面的循环中有缺失的部分和计算,而我列出了从数据库中得到的值。我必须将这些值相加,以便获得总付款,当我调整选择选项时,小计和总付款也会发生变化。