Mysql result was rewinding twice