A method of inhibiting gastrointestinal ammonia-producing bacteria includes administering to a patient in need thereof a rifamycin-quinolizidone dual-action molecule shown in formula I. The rifamycin-quinolizidone dual-action molecule shown in formula I of present invention has an antibacterial spectrum similar to that of rifaximin, stronger antibacterial activity against the gastrointestinal common ammonia-producing bacteria, low frequency for resistance development, and potential use in prevention and treatment of hepatic encephalopathy and related bacterial infections.