I'm not really sure what/how you're showing your selected items. That said, instead of an inner loop for each item in the outer loop, you can do this more efficiently, with only a single loop through each collection by:
a) ordering each collection the same way (eg by ItemID ascending).
b) As you go through each item in the outer loop, you check to see if the current item in the inner loop the same value (in which case write "selected"), or a lower value (shouldn't occur), and in which case advance the inner loop by one step.
So, suppose you have items 1,2,3,4,5,6,7,8 and the user has items 2 and 4 in their basket. Outer array (1,2,3,4,5), Inner Array (2,4)
For the first iteration, the value of the outer array is 1, and the inner array is 2, so you just write out "1"
For the second iteration, the value of the outer array is 2, and the value of the inner array is 2, so you write out "2 selected", -and- advance the inner array to the next element.
For the third iteration, the value of the outer array is 3, and the value of the inner array is 4, so you just write "3"
For the fourth iteration, the value of the outer array is 4, and the value of the inner array is 4, so you write "4 selected", -and- advance the counter for the inner array.
For -all- subsequent iterations (5,6,7,8), you know you have already gone past the last value in the inner array, so you just write them out without having to do any checking.
Cheers
Ken
www.adOpenStatic.com