Page 1 of 1

Object Array Iterator

Posted: Mon Oct 23, 2006 9:49 am
by montecristo
Hi guys,

I have a quick question about storing objects in arrays.

I have a class called customersale, I can store these in an array.

Code: Select all

while ($row = oci_fetch_array ($s, OCI_BOTH)) 
        {
             		 $customersaleid = $row['CUSTOMERSALEID'];
	                 $customersale = new  customersale($customersaleid);
		 echo $customersale->getprice();

		 $customersalearray[$ctr] = $customersale;

		 $ctr =  $ctr + 1;
        }
The class customersale has functions such as getprice(),gettransactiondate() etc....
How do I iterate through this array and retrieve a certain customersale object and apply the class's functions?

Thanks

Posted: Mon Oct 23, 2006 10:00 am
by John Cartwright

Code: Select all

while ($row = oci_fetch_array ($s, OCI_BOTH))
{
   $customersaleid = $row['CUSTOMERSALEID'];
   $customersale = new  customersale($customersaleid);
   $customersalearray[] = $customersale->getprice();
}
Is this what you are after?

Posted: Mon Oct 23, 2006 10:06 am
by montecristo
Thank you for getting back to me so quickly!

What I require is to store the customersale objects in an array. So a customer would have one or many customersale objects. I wish to loop through the array containing the customersale objects and then apply the functions to these objects to get the the price, transaction date etc.

Posted: Mon Oct 23, 2006 10:21 am
by montecristo
Worked it out
Was doing something stupid :oops:

$customersale = $customersalearray[0];
echo ">>>>>>>>>>>>>" .$customersale->getprice();

This was I was attempting to do.

Thank you for replying