How to generate order reports in php?

Hi,
How to generate order reports in PHP? For I am studying some sample codes of PHP from the internet I was confused on how to generate order reports in PHP maybe because there are some codes that having an error specially when connected to database. I need your help anything that is related to this kind of topic, or any downloadable sample codes will help a lot.
Thank you experts.
