Formatting the results of a MySQL query as if it were run from the console

后端 未结 7 2141
清酒与你
清酒与你 2020-12-16 15:04

I\'m writing a quick and dirty reporting script that queries a report and emails the results. When using the MySQL console the results are in a nicely formatted table:

7条回答
  •  北海茫月
    2020-12-16 15:33

    it sounds like you just need to use any one of the exec methods or backticks. I'm not sure about the '\G' thingy... but, I published a php function called query2Table() a few months ago @ http://www.logicwizards.net/php-query2table -- based on a function I've been recycling for years. I have a bunch that I've accumulated over the years: query2xml, query2excel, query2json, etc. I think I still have the old perl & asp versions somewhere, too.

    Basically, in my solution, you can just pass it the query string and it dynamically spit's out an html table using column names fetched from the results as the table's header row. It also grows to fill the width of it's inherited container object.

      query2table("select * from table;");
    

    I have a more up to date version query2AjaxTable() which wraps everything up nicely in a class and adds jQuery sorting & animations -- but it's not ready for publishing yet.

    If my silly little function doesn't help you, in your dilemma, maybe someone else will find it useful...

提交回复
热议问题