Some elementary rules follow:
A reaction will occur if ONE of th following can take place.
a. a gas is formed.
b. a precipitate (insoluble solid) is formed.
c. H2O or another slightly ionized material is formed.
d. redox reactions.
For a you need to know some of the gases. Elements are H2, N2, O2, F2, Cl2 and some common compounds such as CO2, SO2, SO3, NO2, NO, etc..
For b you the solubility rules.
For c, H2O is the most common one; e.g., acid + base ==> salt + water.
For d, the most common ones encountered in first year chemistry come from the activity series.
For the first one in your question, the product that makes the reaction go is the precipitation of th insoluble solid, Mg3(PO4)2.