We help IT Professionals succeed at work.

Psevdo - dynamic tables

hpet
hpet asked
on
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.
Comment
Watch Question

CERTIFIED EXPERT
Commented:
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 http://www.phpclasses.org/browse/package/130.html for a sample class incluing code examples.

Author

Commented:
I guess you are correct.
Unfortunately : ) I don't know what I was really expecting to hear. Just the moment in my thoughts.

Thanks

Explore More ContentExplore courses, solutions, and other research materials related to this topic.