Вопрос

I'm using TBS sample code:

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

  $list = array('X','Y','Z');
  $TBS->MergeBlock('blk', $list);
  $TBS->Show();

but instead of a one column table as below

<table>
  <tr><td>X</td></tr>
  <tr><td>Y</td></tr>
  <tr><td>Z</td></tr>
</table>

I want to get a multicolumn (for instance 4 column) table.

So far the only working code I found is:

$number_of_columns = 4;
$number_of_rows    = 2;
$number_of_items = $number_of_columns * $number_of_rows;
$output_data = array('1', '2', '3', '4', '5', '6', '7', '8');

$TBS->MergeBlock('col','num',$number_of_columns); // expand columns
$TBS->MergeBlock('od',array_slice($output_data,0,$number_of_items));

and as template

<table border="1">
                <tr>[od;block=tr;serial]<td>[od_[col.val;block=td].val;block=td]</td></tr>
</table>

Is there anything simpler?

Это было полезно?

Решение

If what you want to do is to display items sequentially like this

 1  2  3  4
 5  6  7  8
 9 10 11

Then you can :

1) Use the serial mode in TBS just like you example. That is the purpose of that parameter and your example is quite simple.

2) Change the items in your data source $output_data, so that there is one record per row.

Script :

$data = array(
   array(1, 2, 3, 4),
   array(5, 6, 7, 8),
   array(9, 10, 11),
);
$TBS->MergeBlock('od', $data);

Template :

<table>
   <tr>
     <td>[id.0;block=tr]</td>
     <td>[id.1;noerr]</td>
     <td>[id.2;noerr]</td>
     <td>[id.3;noerr]</td>
   </tr>
</table>

3) Don't change the data, instead change the HTML template. Instead of a table, use a <div> with a fixed width. In this div, use an entity that is positioned in line, such as <span> with a width is is the quarter of the <div>. Then each <span> will be displayed sequentially with a line break each 4 <span>.

$output_data = array('1', '2', '3', '4', '5', '6', '7', '8');
$TBS->MergeBlock('od', $output_data);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top