added query and php
made sure the code was order to get last record