doutu4335
2019-01-26 05:05
浏览 106
已采纳

从mysql检索数据并在php页面上显示

I am trying to make a quotation system with php code, I can retrieve data from database, but how can I multiply the data?

for example, quantity times cost.

The code echo "<td>".$row_result['"cost" * "qua"']."</td>"; is what I meant, can someone help me out with this issue.

Thanks

<?php
while($row_result=mysql_fetch_assoc($result)){
    echo "<tr>";
    echo "<td>".$row_result["id"]."</td>";
    echo "<td>".$row_result["gp_name"]."</td>";
    echo "<td>".$row_result["date"]."</td>";
    echo "<td>".$row_result["type"]."</td>";
    echo "<td>".$row_result["checkin"]."</td>";
    echo "<td>".$row_result["checkout"]."</td>";
    echo "<td>".$row_result["country"]."</td>";
    echo "<td>".$row_result["city"]."</td>";
    echo "<td>".$row_result["name"]."</td>";
    echo "<td>".$row_result["arrange"]."</td>";
    echo "<td>".$row_result["qua"]."</td>";
    echo "<td>".$row_result["cost"]."</td>";
    echo "<td>".$row_result['"cost" * "qua"']."</td>";
    echo "<td>".$row_result["reference"]."</td>";

    echo "<td><a href='update.php?id=".$row_result["id"]."'>Change</a> ";
    echo "<a href='delete.php?id=".$row_result["id"]."'>Delete</a></td>";
    echo "</tr>";
    }

?>

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsc862009 2019-01-26 05:49
    已采纳

    If you want to multiply two value in different array location you must access those keys individually.

    $row_result["cost"] * $row_result["qua"]
    
    点赞 打赏 评论
  • duanheye7423 2019-01-26 06:06

    The short answer to your question is to multiply it inline. I'd also rewrite the code to something like this for the sake of clarity and ease of maintenance in the future. Hope this helps, let me know if I can clarify.

    <table>    
     <?php while($row_result = mysql_fetch_assoc($result)): ?>
        <tr>
            <td> <?php echo $row_result["id"]; ?> </td>
            <td><?php echo $row_result["gp_name"] ?></td>;
            <td><?php echo $row_result["date"] ?></td>;
            <td><?php echo $row_result["type"] ?></td>;
            <td><?php echo $row_result["checkin"] ?></td>;
            <td><?php echo $row_result["checkout"] ?></td>;
            <td><?php echo $row_result["country"] ?></td>;
            <td><?php echo $row_result["city"] ?></td>;
            <td><?php echo $row_result["name"] ?></td>;
            <td><?php echo $row_result["arrange"] ?></td>;
            <td><?php echo $row_result["qua"] ?></td>;
            <td><?php echo $row_result["cost"] ?></td>;
            <td><?php echo $row_result["cost"] * $row_result["qua"] ?></td>        
            <td><?php echo $row_result["reference"] ?> </td>
        </tr>
     <?php endwhile; ?>
    </table>
    
    点赞 打赏 评论

相关推荐 更多相似问题