我将mysql数据库填充到html表中,现在我要做的是将价格和数量相乘以便找到总数以便在另一列中显示。这些都是关于一张桌子的。
"SELECT * FROM orders where user_id = '".$_SESSION['userId']."' ORDER BY order_id DESC";
这是我的sql语句。这是我的相关php代码:
foreach( $result as $data )
{
echo "<tr><td>".$data['order_situation']."</td>
<td>".$data['client_name']."</td>
<td>".$data['client_last_name']."</td>
<td>".$data['city']."</td>
<td>".$data['district']."</td>
<td>".$data['area']."</td>
<td>".$data['address']."</td>
<td>".$data['tel_no1']."</td>
<td>".$data['tel_no2']."</td>
<td>".$data['product']."</td>
<td>".$data['quantity']."</td>
<td>".$data['price']."</td>
<td>".$data['down_payment']."</td>
<td>".$data['explanation']."</td>
<td>".$data['username']."</td>
<td>".$data['date']."</td>
<td><a href=\"updateorders.php?id=".$data['order_id']."\">Güncelle</a></td>
</tr>";
}
答案 0 :(得分:1)
"SELECT *, price * quantity AS total FROM orders WHERE user_id = '".$_SESSION['userId']."' ORDER BY order_id DESC";
那应该有用。然后你可以参考总数:
$data['total']