all mysql codes here with some php magic