Yeah, This is a bit complex to answer but the idea is.
-
On a product page, retrieve the current product.
-
Look up the product in your relatedProducts database.
-
Display the product you found in the relatedProducts.
Therefore the related Products will change depending on the product you are viewing.
I would advice you to learn how to work with collection and collection references