Psevdo - dynamic tables

Posted on 2008-01-30
Medium Priority
Last Modified: 2011-09-20
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.
Question by:hpet
LVL 34

Accepted Solution

Beverley Portlock earned 1000 total points
ID: 20785286
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 Closing Comment

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


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

594 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question