awk if statement in a for loop?

I need to match multiple values in a single column in a file:
example:

Source file:

abd,123,one
def,232,two
ghi,987,six

Target file:

12345,abcde,123
09876,zxvyr,566
56789,lmnop,232

Variable:

var1=`grep 2 sourcefile | awk '{print$1}' 

essentially, echo "$var1" would read:

123
232

For loop:

for variable in ${var1[]}
do
cat targetfile | awk '{if ($3 == "$variable") print $1;}' > outputfile
done

in theory, the result set should be...

12345
56789

...however, when I run this, I get no errors but no output. I don't know where i've gone wrong. Any help would be greatly appriciated.

Thanks!

With awk, field delimiter , :

grep 2 sourcefile | awk -F, 'NR==FNR {A[$2]; next} ($3 in A) {print $1}' - targetfile

If NR == FNR (true for File1, here - == stdin == pipe) then store in array A, key is $2 (field 2) and jump to next line. Otherwise (not File1, i.e. in targetfile ), if $3 (field 3) is in array A, print $1 (field 1)
All in one awk:

awk -F, 'NR==FNR {if ($0~search) A[$2]; next} ($3 in A) {print $1}' search=2 sourcefile targetfile

I"ll give that a try, Thanks.