Jay Blanchard <mailto:[EMAIL PROTECTED]>
    on Monday, September 19, 2005 10:53 AM said:

> I think that it should be a stand alone class. The Customers class
> could instantiate the needed number of Customer objects and the
> methods of the Customers class could affect each Customer object.

I'm stuck on how I convert 'SELECT id, name FROM customers WHERE id >
nn' into "the needed number of Customer objects".

Here's an attempt:

class Customers
{
        var $customers = array();

        function get_customers($sql)
        {
                // instantiate db object
                $db = new DB::singleton();

                // get results of $sql
                $results = $db->execute($sql);

                foreach($results as $v)
                {
                        // instantiate one Customer object
                        $tmp = new Customer;

                        // populate it with data
                        $tmp->id   = $v['id'];
                        $tmp->name = $v['name'];

                        // store it in array
                        $this->customers[] = $tmp;
                }
        }

        function delete_customers()
        {
                // loop through array of customer objects ...
                foreach($this->customers as $customer_obj)
                {
                        // ... deleting each customer one at a time
                        $customer_obj->delete_customer();
                }
        }
}



Thanks,
Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to