This project is read-only.

Restriction Operators :: Where - Drilldown

This sample prints a list of customers from the state of Washington along with their orders. A sequence of customers is created by selecting customers where the region is 'WA'. The sample uses doubly nested foreach statements to print the order numbers for each customer in the sequence.

function linq4() {
    List customers = GetCustomerList();
    $customers = getCustomerList();

    $waCustomers = from('$c')->in($customers)->where('$c->Region == "WA")->select('$c');

    echo "Customers from Washington and their orders:<br />";

    foreach ($waCustomers as $customer)
    {
        echo "Customers ".$customer->CustomerID.": ".$customer->CompanyName."<br />";
        foreach ($customer->Orders as $order)
            echo "Order".$order->OrderID.": ".$order->OrderDate."<br />";
    }
}

Result

Customers from Washington and their orders:
Customer LAZYK: Lazy K Kountry Store
Order 10482: 3/21/1997 12:00:00 AM
Order 10545: 5/22/1997 12:00:00 AM
Customer TRAIH: Trail's Head Gourmet Provisioners
Order 10574: 6/19/1997 12:00:00 AM
Order 10577: 6/23/1997 12:00:00 AM
Order 10822: 1/8/1998 12:00:00 AM
Customer WHITC: White Clover Markets
Order 10269: 7/31/1996 12:00:00 AM
Order 10344: 11/1/1996 12:00:00 AM
Order 10469: 3/10/1997 12:00:00 AM
Order 10483: 3/24/1997 12:00:00 AM
Order 10504: 4/11/1997 12:00:00 AM
Order 10596: 7/11/1997 12:00:00 AM
Order 10693: 10/6/1997 12:00:00 AM
Order 10696: 10/8/1997 12:00:00 AM
Order 10723: 10/30/1997 12:00:00 AM
Order 10740: 11/13/1997 12:00:00 AM
Order 10861: 1/30/1998 12:00:00 AM
Order 10904: 2/24/1998 12:00:00 AM
Order 11032: 4/17/1998 12:00:00 AM
Order 11066: 5/1/1998 12:00:00 AM

Last edited Nov 1, 2008 at 10:41 PM by vojtechzicha, version 1

Comments

No comments yet.