fetch_assoc(); $existing_data = $existing_data_res->fetch_assoc(); $pending_orders = 0; $active_orders = 0; $delivered_orders = 0; foreach($orders_res as $order) { $order_item = mysqli_query($conn, "SELECT * FROM order_item WHERE order_id = {$order['id']};"); $total_sum = 0; foreach($order_item as $item) { $total_sum = $total_sum + ($item['quantity']*$item['price']); } switch($order['status']) { case 'p': ++$pending_orders; break; case 'a': ++$active_orders; break; case 'd': ++$delivered_orders; break; default: break; } } ?>