checking if $records is array before looping