Hi Guys,
I'm from a VB; Access; SQL Server background recently introduced to WAMP.
I have two arrays filled from MySQL recordsets, one for the site Cart and the other for one of the site departments (catalogs) see a manual interpretation below.
What I need to do is loop through the catalog array each time a new catalog is chosen, comparing the ProdID of the cart against the catalog, when a match is found I would like to update the 'InBasket' value to '1' this will indicate the item is already in the customers cart which I can then show on screen (The customer is only allowed to purchase one of each item).
I have tried some loops but they don't seem to work.
Any ideas would be appreciated.
I'm from a VB; Access; SQL Server background recently introduced to WAMP.
I have two arrays filled from MySQL recordsets, one for the site Cart and the other for one of the site departments (catalogs) see a manual interpretation below.
Code:
$catalog[] = array( array('ProdID'=>2,'Name'=>'Alpha','DepID' =>2,'InBasket'=>'0'), array('ProdID'=>6,'Name'=>'Alpha','DepID' =>2,'InBasket'=>'0'), array('ProdID'=>7,'Name'=>'Alpha','DepID' =>2,'InBasket'=>'0'), array('ProdID'=>8,'Name'=>'Alpha','DepID' =>2,'InBasket'=>'0'), array('ProdID'=>9,'Name'=>'Alpha','DepID' =>2,'InBasket'=>'0'), ); $cart[] = array( array('Name'=>'Alpha2','Loc'=>'e_vol1','BasketID'=>'81','ProdID'=>'2','Quant'=>'1'), array('Name'=>'Beta4','Loc'=>'e_vol2','BasketID'=>'81','ProdID'=>'4','Quant'=>'1'), array('Name'=>'Alpha8','Loc'=>'e_vol3','BasketID'=>'81','ProdID'=>'8','Quant'=>'1'), array('Name'=>'Gamma21','Loc'=>'e_vol4','BasketID'=>'81','ProdID'=>'21','Quant'=>'1'), );
I have tried some loops but they don't seem to work.
Code:
for ($x = 0; $x < count($catalog); $x++) { for ($y = 0; $y < count($cart); $y++) { If ($catalog[$x]['ProductID'] == $cart[$y]['ProductID'] ) { $cart[$x]['InBasket'] = 1; } } }
Comment