This script is a variation on Table with multi-page columns. The difference is that when a query is executed initially the php loops through, gathers the string widths and then resizes the columns to try and fit everything onto the page. If a column never uses the maximum width alloted to it, the column is sized down and the saved space is re-assigned to the other columns. The aim of this was to be able to get out a good looking mysql report using as few a lines as possible, the disadvantage is that because the query has to loop through the results to work out the column sizes, it takes a bit of time. To counteract this, there is a dump option, that dumps out the php required to set up column widths, so one could check with a small report that the columns looked okay, then apply the dumped column widths to a larger report.
Now issued under the CC share-a-like attribution licence 4.0 (use it freely for any purpose just mark up your changes which is basically common sense as it makes bug fixing easier).
Can now use multiple SQL statements to get report tables on one page, e.g. older version would do "November Sales Report", then another PDF would need to be generated for the next Sales report (typically by a posted SQL query or cron job saving to different file), whereas now you can put all your sales reports into one page using multiple SQL queries (still recommend running the report on a cron job and outputting it, but altering the PHP so that one does not even need to post data to create the reports).
After filling out your FPDF library and DB details, then adding a SQL statement, this script outputs a PDF. It has been running reliably since 2003 with minor changes, and this version is the first major alteration where it now uses the mysqli functions. The file ex.php contains lots of comments to help with creating your own reports. To create your own reports I recommend just taking ex.php renaming it, filing in the details, removing all except one the examples, which you use as a template and running it on your server.
Also included now at the top of ex.php are ini_set statements to turn on and off error_reporting and display_errors in the file itself to aid you in your debugging (nothing worse that a blank page with no info because of your server settings ;-). Over the years the most common bugs have been
The most common question has been "how do I change the column titles", that's simple, it's done in SQL and is very easy with an example now in ex.php.
Large sums of money deposited in Swiss bank accounts/ blank signed cheques made out to cash; always appreciated...
-- thank you, Philip Clarke