How do I control flatulence?

Avoid certain foods. Eating a healthy diet can cause gas due to excess fiber. Since humans don't digest the fiber, intestinal bacteria will eat it and make gas as a byproduct. "beano" enzyme may help. Another reason is lactose intolerance, in which one can't digest lactose (milk sugar). "lactaid" tablets help. A third reason is sugar alcohols, like maltitol, that can cause gas. The doctor can look for other causes.
What's the cause? Flatulence neither localizes your problem to the small or large bowel, nor indicate severity or cause. You have described a gut that may be dysfunctional--but is this due to infection, sibo, motility problems, inflammation, ibs, ischemic disease, maldigestion, sphincter problem, etc.? How long have your symptoms lasted, is there accompanying fever, bleeding, vomiting, tenderness? Help w/more info.