so sad

I had a chemical pregnancy nov 16th and got pregnant again around dec 1st.. it is now jan 28 and Im 9 weeks but they said i do not have a heart beat on the baby so I have to terminate it... im so sad this will be two miscarriage back to back does this have anything to do with getting pregnant immediately before my period ? will this continue