BarryG Posted November 3, 2011 Share Posted November 3, 2011 Hello, I've created the E-Commerce shopping cart using the Chapter 17 example and all works great! The problem I have is on the confirmation page, I can list the completed order items (code below) by querying the orders table in the database, but how do I repeat this to put into the $body of a confirmation email? I'm guessing it's creating an array, but how do I assign the output of the array (all 'item name and price' results) into one variable to go into the email $body? Thanks, Barry. The section of code is: // Message to the customer: echo '<h1>Order Complete</h1> Thank you, you\'ll shortly receive an email receipt confirming your purchase. <br><br> ***************************************************************<br> <b>Order Details:</b><br> ***************************************************************<br><br> Order Reference: <b>'; echo $orderref; echo "</b> <br><br> <table width=\"600\" align=\"left\">"; $query = "SELECT item_name, price FROM orders"; $result = mysqli_query($dbc, $query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysqli_error($dbc)); while($row = mysqli_fetch_assoc($result)) { echo "<tr> <td style=\"border: none\" width=\"250\">{$row['item_name']}</td> <td align=\"right\" style=\"border: none\" width=\"50\">£{$row['price']}</td> <td style=\"border: none\" width=\"300\"></td> </tr>"; $subtotal = array($row['price']); $total += array_sum($subtotal); } echo " <tr><td colspan=\"3\" style=\"border: none\" width=\"600\"></td></tr> <tr> <td style=\"border: none\" width=\"250\"><b>Total</b></td> <td align=\"right\" style=\"border: none\" width=\"50\"><b>£$total</b></td> <td style=\"border: none\" width=\"300\"></td> </tr> <tr><td colspan=\"3\" style=\"border: none\" width=\"600\"></td></tr> </table> ***************************************************************<br><br> Link to comment Share on other sites More sharing options...
Larry Posted November 5, 2011 Share Posted November 5, 2011 This is a common enough question and actually easier than it seems. Before the loop, initialize a variable as an empty string: $body = ''; Within the loop, just concatenate whatever you want on to $body. After the loop, use $body as you see fit! Link to comment Share on other sites More sharing options...
Recommended Posts