the 'fid' AND 'ftdid' should not be hardcoded if it can be helped, you probably need either a more complicated SQL statement or a php loop here.