Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $conn = mysqli_connect("127.0.0.1", "root", "ascent", "world");
- $stmt = $conn->prepare("SELECT * FROM tablename");
- $stmt->execute();
- $result = $stmt->get_result();
- if($result->num_rows > 0) {
- while($rows = $result->fetch_all(MYSQLI_ASSOC)) {
- $price = array_column($rows, 'price'); // <== price is column name of the price column. So you may replace this if the name of column is not price
- $sumprice = array_sum($price);
- foreach($rows as $row) {
- echo nl2br("item name: ".$row['name']." Price: ".$sumprice."\n"); // You may also replace name in $row['name'] with another column name... Or you can just simply remove it
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement