I am trying to pull customers orders from my database, however the code I currently have only shows data from one order, but the customer may make more than one order. Because of this I know I need to add a foreach loop, however I am new to them and am unsure of the exact location and how to use it with my code. My $order_id variable shows both $order_id's so I think it needs to go above $order_detail, so for each order_id, display the details
function viewOrders($session_mem_id){
//This block grabs the orders
$order_list = "";
//Selecting all the orders in the table from that member
$sql = mysql_query("SELECT `order_id` FROM `transactions` WHERE `mem_id` = $session_mem_id") or die(mysql_error());
$orderCount = mysql_num_rows($sql);
if ($orderCount > 0) {
while($row = mysql_fetch_array($sql)){
//creating variables from the information
$order_id = $row["order_id"];
}
$order_details = mysql_query("SELECT * FROM `transactionDetails` WHERE `order_id` = $order_id") or die(mysql_error());
$orderDetailsCount = mysql_num_rows($order_details);
while($row = mysql_fetch_array($order_details)){
//creating variables from the information
$order_product_id = $row["Product_ID"];
$order_product_price = $row["Price"];
$order_product_quantity = $row["Quantity"];
$order_List .='<tr>';
$order_List .='<td>' . $order_id .'</td>';
//$order_List .='<td><a href="product.php?id=' . $order_product_id . '">' . $product_name . '</a></td>';
$order_List .='<td>£' . $order_product_price .'</td>';
$order_List .='<td>' .$order_product_quantity .'</td>';
$order_List .='</tr>';
}
} else {
//displaying a message if no products were found
$order_list = "You have no orders to display";
}
print_r($order_List);
}