如何在PHP的while循环中计算乘法值? [英] How to calculate multiplication value inside the while loop in PHP?

查看:74
本文介绍了如何在PHP的while循环中计算乘法值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个while循环,它显示数据库中的数据.现在,我想将两个值乘以一行并在同一行中显示结果,以相同的方式将值乘以并在每一行中显示结果.我没有得到结果.谁能帮我?我是PHP新手.

I have one while loop which displays data from the database. Now I want multiply two values in one row and display the result in the same row, the same way multiply the values and display the result in every row. I am not getting the result. Can anyone help me? I am new to PHP.

while($row = mysql_fetch_array($result))
{
   echo "<tr>";
   echo "<td class='alt'>" . $row['id'] . "</td>";
   echo "<td>" . $row['item'] . "</td>";
   echo "<td>" . $row['amount'] . "</td>";
   $ss=$row['amount'];
   echo '<td >'.'<input type="checkbox"  name="status" value="" >'.'</td>';
   echo '<td >'.'<input type="text" name="qty">'.'</td>';
   echo "<td>" . $rr1 . "</td>";
   echo "</tr>";
 }

推荐答案

将查询更改为

$result= mysql_query("Select id, item, amount, (item * amount)  total
 from table_name");

然后进入while循环

then in while loop

while($row = mysql_fetch_array($result))
    {
       echo "<tr>";
       echo "<td >" . $row['id'] . "</td>";
       echo "<td>" . $row['item'] . "</td>";
       echo "<td>" . $row['amount'] . "</td>";
       echo "<td>" .($row['total']  "</td>";
       echo "</tr>";
     }

这篇关于如何在PHP的while循环中计算乘法值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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