I added logic that would enable you to feed it multiple search names
you could either have a set # of search text inputs named "affiliate1", "affiliate2", etc... and then $numAffiliates would just be hard-coded as the number of inputs.
or you could dynamically add search input fields and then pass the number of those to this script as a hidden form element named "numAffiliates"