Presenting tabular reports in the 'content' area.
I'm fairly new to Drupal. I've gone through the Pro Drupal Development book, the IBM online series that was based on 4.7, and the module building tutorials available here and elsewhere. I've written a few simple modules and have become decent at working the Forms API.
But...I need to query a separate database (easy part) and represent tabular reports in the "content" area of the page. Ideally I'd have a few templates into which I could place variables through which I'd loop to present the report data.
I'm not sure how to do this, though. Most of the tutorials talk about how to create your own page/node/block/box templates. I get that, it's pretty straightforward, but I'm struggling with the current challenge.
Ideally the flow would be like this (or this is how I'd do it using a Front Controlled framework with a template system).
1) Store the report meta data (title, filtering critera, etc) into variables.
2) Query the database and store the results into an object or array variable.
3) "Load" the template that itself references the variables set in steps 1 and 2 and renders the data.
4) "Load" the master template that renders the header, footer, nav, etc.
Thank you for any advice you can offer.

(no title)
If you use nodes with custom fields as input forms, then you can easily use table views (Views module) for your reports.
Otherwise you can create dynamic tables straight inside a node, using the "PHP code" input format and printing the HTML tags and the variables.
There is also the tablemanager module which might help with tables in a node. Perhaps its tablemanager_display() function can make the above procedure easier. (I haven't tried it myself). See: http://drupal.org/project/tablemanager
Thanks for your replay,
Thanks for your replay, cog.rusty.
There is no user input with the exception of login/authentication. The data for the reports is actually from another system; we're just using Drupal as the frontend because it has decent ACL and because it offers CMS functionality that is needed on a portion of the site totally unrelated to what I'm doing.
So I'm not really dealing with a "node" as I understand it. I understand a "node" to be the way that Drupal universally treats user contributed data, but in this case there is no user contributed data. Perhaps this displays a lack of understanding of Drupal on my part.
Custom node type(s), perhaps? This would allow me to designate the content template...or maybe that's not the right approach...
(no title)
A node is Drupal's unit of content, a "posting". It can come either from a user or from yourself.
Different node types, such as "story", "page", "blog entry", or additional custom ones which you have created in /admin/content/types can offer different workflows (published, promoted etc) and different access permissions (for example, "can be created only by an editor user role").
Additionally, by installing the CCK module, different node types can have not only a title and a body but also additional fields (text, numeric, reference, matrix etc) which you have added in their definition. That is what I meant by "using it as an input form", in which case you would be able to pull nodes into a table view using the Views module, which is essentially a query generator creating a page with data from nodes.
However all this is purely academic, since your database rows do not correspond to nodes. So, probably you would put your table in the body of a single node using PHP like this:
<?php...some db queries and processing code...
...
$output = '<table>';
foreach($myvariables as $variable) {
$output .= '<tr>';
$output .= '<td>' . $variable['blah'] . '</td>';
$output .= '<td>' . $variable['bleh'] . '</td>';
$output .= '</tr>';
... etc...
}
$output .= '</table>';
print $output;
?>
The tablemanager module and especially its tablemanager_display() function, which I mentioned, "might" make this more painless. Another module which could help clone this to more nodes and modify it as some kind of template is http://drupal.org/project/node_clone
Am I try to make Drupal do
Am I try to make Drupal do something it wasn't designed to do? Outputting HTML from PHP is pretty kludgy.
(no title)
I don't think so. That's how Drupal prints all its output from the theme's page.tpl.php file and the other template files. Of course you would be bypassing Drupal's available means, but then again, you need to print external data. Also, the handbook is full of code snippets meant to be placed in blocks or nodes to print something which is not available.
However, if you want to try to print your output though a module of yours and not directly in the content, you may find this module useful:
http://drupal.org/project/object_driver
I'm checking out the modules
I'm checking out the modules that you recommended, cog.rusty. Thanks for the steer.
So is the deal that the PHPTemplate system and associated functions in Drupal can only be used to render data that is obtained from formal Drupal "types," i.e., nodes, blocks, etc?
(no title)
People often use the theme template files for directly printing other things such as banners, ads etc, which is reasonable, but yes, its main function is to print Drupal entities.
So, with Drupal nodes or blocks you can have Drupal handle things such as placement and visibility (on which pages they appear, to which users they will be visible etc). Using nodes and blocks for your content is a matter of taking advantage of Drupal functionality.
Also, being able to use functions from http://api.drupal.org instead of generic mysql queries and generic php is often valuable for access control and for combining your data with Drupal entities without having to dig too deep into the database schema.