It can either be something "off" you ate or just an infection. These "bugs" are very contagious which is why whole families or boarding schools end up having diarrhoea. (infection is anal-oral; meaning if someone hasn't washed their hands properly after having been to the loo, touches something, let's say a doorknob and you touch it shortly afterwards and then finger your nose/mouth you could catch it)
Usually these things don't persist longer than 48hrs and as suggested above you should keep well hydrated. Drinking weak black tea with some sugar and a pinch of salt helps (NO milk), eating prezels or stale bread is good. Avoid fat for 2-3 days and build up your food slowly over 1-2 days.
If the problems persists (>48hrs) or blood comes it could be an infection with salmonella enteritis which has to be treated, or an inflammation of the bowel "colitis", which also needs treatment. Then you should go to the doctor's.