How long for UTI to clear up?

So 3.5 weeks ago I went to urgent care because I thought I had a UTI. They did a dip stick and told me I did and they gave me Bactrim. The day after I stopped the Bactrim I started having a lot of pain in my pelvis on the right side all the way up my back. I thought maybe it was trapped gas but it just kept getting worse and worse as the days went by and then I started running a fever. I went to the ER on Saturday because I thought it was serious. They did a CT scan and said my kidney, ovary and appendix look good so they told me it was a really bad UTI. They gave me IV Rocephin and then sent me home with Macrobid. I’m still in quite a bit of bad pain and am just wondering how long this Macrobid will work? I’m so miserable. It feels like I’m getting stabbed in the abdomen. They told me to come back to the ER if I start running a fever again.