我有一个while循环显示来自数据库的数据。现在我想在一行中将两个值相乘并在同一行中显示结果,以相同的方式将值相乘并在每一行中显示结果。我没有得到结果。谁能帮我?我是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>";
}
答案 0 :(得分:0)
从哪里获得$rr1
??
你可以拥有
echo "<td>" . $row['item'] * $row['amount'] . "</td>";
希望这就是你想要的......
答案 1 :(得分:0)
答案 2 :(得分:0)
尝试以下:
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>";
echo "<td>" .($row['item'] * $row['amount']). "</td>";
echo "</tr>";
}
答案 3 :(得分:0)
将查询更改为
$result= mysql_query("Select id, item, amount, (item * amount) total
from table_name");
然后在while循环中
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>";
}