UTI Questions, Advice, Info

Recently had sex for the first time and instead of knowing what I know now, I didn't use the bathroom right after. So, due to that, I got a UTI. So I just wanted to know some tips/advice on what to do next time so that I don't receive another UTI. Also, how long did you all wait after the antibiotics to have sex again?