Depending on what kind of magnesium you take, it can do different things to you.
Have you ever tried OxyPowder? It's an Oxygen Colon Cleanser that is commonly used as a safer alternative to laxatives. One of the main ingredients is Magnesium Oxide.
You mentioned that you get diarrhea when you take magnesium supplements. I'm not totally sure how all magnesium supplements work, but I know with Oxypowder, you are supposed to experience liquedy stools. These liquedy stools are similar to diarrhea, but thats not what it is, it's actually a result from the oxidation process of the feces in your intestines. I have used Oxypowder for a long time and it works great. Maybe you should look into that...
Either way.. I hope you get it balanced soon! Good Luck!