Categories > TinyButStrong general >

Printing entire table

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: NeedBeans
Date: 2004-03-25
Time: 22:42

Printing entire table

Hi,

This is either a request for some help or a feature request. At a couple of places I had the need to show an entire table, including headers. Using tbs I have to give in the headers in the template myself. And I don't want that. I've come up with the solution below. I MergeBlock both the result and twice the header. Now I can edit the query and it will always display the result. Very useful! But I think it should be possible to do this easier with tbs. My question is whether this is currently possible ? (If not, I think it should be a feature vor v2 :) )

Mike

/* Connect to db */
$link = mysql_connect('localhost','default' ,'') or die("Could not connect : " . mysql_error());
mysql_select_db('kassa') or die("Could not select database");

$sql = "select * from table";
$rs = mysql_query($sql);
$row = mysql_fetch_array($rs,MYSQL_ASSOC);
$header = array_keys($row);

include_once('tbs_class.php');
$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('print.html') ;

$TBS->MergeBlock('header1',$header);
$TBS->MergeBlock('header2',$header);
$TBS->MergeBlock('array','mysql',$sql);
$TBS->Show();

<table border=1>
    <tr>
        <th>[header1.val;block=th]</th>
    </tr><tr>
        <td>[array.[header2.val;block=td];block=row]</td>
    </tr>
</table>
By: Skrol29
Date: 2004-03-26
Time: 23:08

Re: Printing entire table

Hi,

You can inprove you solution a bit.
The following code doesn't need to execute the sql twice, and also works fine if the sql returns no data.

I alos think this is a very specific need because using * in queries is disadvised for applications. But I guess this is a special need.

HTML:
<table border=1>
<tr>
<th>[header1.val;block=th]</th>
</tr><tr>
<td>[array.[header2.val;block=td];block=row]</td>
</tr>
</table>

PHP:
$sql = "select * from table";
$rs = mysql_query($sql);

//Build field array
$fld = mysql_num_fields($rs);
$header = array();
for($i=0;$i<$fld;$i++) {$header[$i]=mysql_field_name($rs,$i);}

include_once('tbs_class.php');
$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('print.html') ;

$TBS->MergeBlock('header1',$header);
$TBS->MergeBlock('header2',$header);
$TBS->MergeBlock('array','mysql',$rs);
$TBS->Show();