简体   繁体   English

如何在php和mysql中做乘法

[英]how to do multiplication in php and mysql

I need to multiply the price by the quantity to get the total cost but i am not sure how to do this.我需要将价格乘以数量以获得总成本,但我不知道如何做到这一点。

This is what i have done so far:这是我到目前为止所做的:

<?php do { ?>
    <p align="Center"> 
        <?php echo $row3['unitprice'] ?> 
        <?php echo $row3['quantity']; ?>
    </p>
<?php } while ($row3 = mysqli_fetch_assoc($resultCustomer3))?>

at the moment i am only printing out unit price and the quantity.目前我只打印单价和数量。

how would i multiply the two to get the total?我如何将两者相乘以获得总数?

HELP please!!请帮忙!!

Try this尝试这个

<?php  while ($row3 = mysqli_fetch_assoc($resultCustomer3)) {?>
<p align="Center"> 
    <?php echo $row3['unitprice']; ?> 
    <?php echo $row3['quantity']; ?>
    <?php echo $row3['quantity']*$row3['unitprice']; ?>
</p>
<?php } ?>

To multiply two fields in php, you need this code:要在 php 中将两个字段相乘,您需要以下代码:

$total = $mnth_190 * $rate_190;

After having calculated the result, you can normally output the variable total !计算出结果后,就可以正常输出变量total了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM