更改PHP和JavaScript小计值 [英] Change values of subtotal in PHP and JavaScript

查看:118
本文介绍了更改PHP和JavaScript小计值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code,到目前为止,我想我的计算分类汇总得到总的支付。谁能帮助?

  $ viewx =的mysql_query(选择ordercontainer那里toordercategory ='$ ordercategory和客户id = $客户ID不同toorderid)或死亡(无法执行SELECT查询。 mysql_error());
而($一行x = mysql_fetch_array($ viewx))
{
    的$ id = $一行x ['toorderid'];    $视图=的mysql_query或死亡(无法执行SELECT查询.mysql_error())(从产品,其中MENUID ='$ ID'和状态=活动选择*);
    而($行= mysql_fetch_array($视图))
    {
        $项目= $行['项目'];
        $细节= $行['细节'];
        $价格= $行['价格'];        呼应'< TR>< TD>'。$项目;
        呼应'< D​​IV的风格=保证金:0像素0像素0像素5像素>'。$细节'< / DIV>< / TD>';
        呼应'&LT; TD&GT;&LT;选择名称=数量的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>';
        呼应'&LT; TD ALIGN =中心&GT;'。$的价格。'&LT; / TD&GT;';
        $数量=;
        $ totalprice =;
        $ =小计($ totalprice * $数量);
        $ totalpayment = $小计;
        呼应'&LT; TD ALIGN =中心&GT;'。$小计。 PHP与LT; / TD&GT;&LT; / TR&GT;';
    }
}


解决方案

首先...你要打印一个选择框在PHP中......这不是问题,问题是PHP期望选择的价值在回收箱来计算的总价格。一个更好的解决办法是让PHP写的一切,因为它是除了计算部分...那么的JavaScript计算总价格为您在选择框的onchange事件。然后让jQuery的结果追加到大部地区。

祝你好运。

I have the following code so far, I want to compute my subtotal to get the total payment. Can anyone help?

$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>';
    }
}

解决方案

First of all... you are printing a select box in PHP... that's not the problem, the problem is PHP is expecting the value of the select box in return to compute the total price. A better solution would be to have PHP write everything as it is, except for the computing part... then have JAvascript compute the total price for you in the onchange event of the select box. And then have jquery append the result to the subtotal area.

Good luck.

这篇关于更改PHP和JavaScript小计值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆