简体   繁体   中英

retrieve data from mysql and display on php page

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>";
    }

?>

如果要在不同的数组位置上将两个值相乘,则必须分别访问这些键。

$row_result["cost"] * $row_result["qua"]

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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