frequent utis

iv had utis for years now and after having sex a while ago i thought i had one, i had the burning the urge to pee and blood in my urine so i went to the doctors and they told me it wasn’t a uti it was maybe jus the start of one but before i went to the doctor i took left over antibiotics from when i actually had one and the doctor said that’s what made it go away. but sometimes now even if i pee after sex i still get the burning the urge to pee and a little blood but they go after taking my antibiotics that i still have but i jus wan know why tf it keeps happening anybody have any ideas?