In Spain you can walk into a pharmacy and get products such as antibiotics over the counter without a prescription - but note that if you have a prescription you will be able to redeem the costs so keep receipts and papers for reimbursement if applicable.
Pharmacies are generally open between 9.30am - 2pm and 5pm - 9.30pm Mondays to Fridays, from 9.30am to around 2pm on Saturdays. There should be contact details there for a 24-hour pharmacy.
Doctors in the emergency departments of state health service hospitals will prescribe medicines on the appropriate medical report, but do not issue official prescriptions. You should take the report to a primary care doctor who will write a prescription for you.
You can collect medicines prescribed by health service practitioners from any pharmacy ('farmacia') and you will have to pay up to 40 per cent of the cost unless you are a UK or European Economic Area (EEA) pensioner, in which case the medicines will be free of charge.