Psevdo - dynamic tables

Don't know how well title described my question, but anyway.
Did you ever try to present tabular data which would be somehow defined at one place only?
For example, I define table structure at one place only (database and presentation) and then preaty much everything else would be handled by some general rutines:
1. create table header
2. request only defined columns from database
3. show result

I thought I could create a key/value array where key would be db field name and value is header title. I could easly build sql statement and so on.

BUT, then I always start to think: what if I want more a complex db query? concatenated fields, joins, etc.?

Idealy I would like one rather "simple" definition statement which would declare everything for some general universal routines to show table.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Beverley PortlockCommented:
Back in 1936 Turing proved that you cannot create a completely general program, so starting from there...

What you can do is create a class (and there are many out there) that allow you to add rows to a table, allocate CSS class to cells and sort out column spans. For instance code like this

$tab = new myTable( array("heading1", "heading2", "heading3");

$tab->addRow( array( $col1, $col2, $col3 ) );
$tab->addRow( array( $wideCol ), array( 3 );   // spans 3 columns

echo $tab->showTable();

You will never get a completely general solution so aim for something that sorts out 80% of your problems. Try here for a sample class incluing code examples.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hpetAuthor Commented:
I guess you are correct.
Unfortunately : ) I don't know what I was really expecting to hear. Just the moment in my thoughts.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.