How to calculate multiplication value inside the while loop in PHP?

后端 未结 4 1061
臣服心动
臣服心动 2021-01-26 14:09

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

相关标签:
4条回答
  • 2021-01-26 14:50

    Try below :

     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>";
         }
    
    0 讨论(0)
  • 2021-01-26 14:57

    you can try

    printf('amount is %d',$row['item'] * $row['amount']);
    

    reference

    0 讨论(0)
  • 2021-01-26 15:00

    Change the query as

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

    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>";
         }
    
    0 讨论(0)
  • 2021-01-26 15:07

    From Where you are getting $rr1??

    You can have

    echo "<td>" . $row['item'] * $row['amount'] . "</td>";

    Hope this is what you want...

    0 讨论(0)
提交回复
热议问题