By: Skrol29
Date: 2005-01-01
Time: 00:00
|
Merge table with dynamic number of columnsHello,
A question which comes back often is how to merge an Html table with a variable number of columns. What we want:
dX-Y : value of data item of column X at the row Y. Here is a solution for a case where we want to display the content of a MySQL table without knowing its columns. This example also shows rows with alternative display. HTML:
PHP:
Note: it needs to have one different column's block for each row of the table. In the example, the table in the template has 3 rows, so we need 3 column's blocks: 'col_1', 'col_1' and 'col_3'. They are merged all tree in only one MergeBlock() call. Enjoy, |
|||
By: magicktrickpony
Date: 2005-07-12
Time: 13:06
|
Re: Merge table with dynamic number of columnsHi-ho!!!
After spending _countless_ hours of trying to get this example to work, I would like to point out that: 1.) If you start counting from Zero the for loop needs to adapted to
2.) Sillyness to teh extreme: if you are a whitespace freak just like me and type:
3.) If you are using postgres you might like to use this code:
Au revoir!!! --ye olde pony |
|||
By: magicktrickpony
Date: 2005-07-15
Time: 14:23
|
Re: Merge table with dynamic number of columnsYes!! Because I am thoroughly bored I would like to include an example code for ADOdb library for PHP (http://phplens.com/lens/adodb/docs-adodb.htm)
Cheers!!!!!!!! --thepony |
|||
By: Skrol29
Date: 2005-07-15
Time: 15:04
|
Re: Merge table with dynamic number of columnsThanks ThePony :)
By the way: >$TBS->MergeBlock('col_0, col_1, col_2', $col); >it won't work. Is this a bug - possiblement??? It's not a bug, it's only not supported (yet). But it could be easily supported. |
|||
By: thuc101
Date: 2010-03-15
Time: 08:38
|
Re: Merge table with dynamic number of columnsthank Scrok29, very good
but some change for ($i=0;$i<=$iMax;$i++) $col[$i] = mysql_field_name($i); by: for ($i=0;$i<$iMax;$i++) $col[$i] = mysql_field_name($res,$i); |