-
Notifications
You must be signed in to change notification settings - Fork 12
/
ex8.php
66 lines (48 loc) · 1.36 KB
/
ex8.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* example 8
* demonstrates how to do good table rows and columns :)
*
* @package XTemplate_Examples
* @author Jeremy Coates [[email protected]]
* @copyright Jeremy Coates 2007
* @see license.txt BSD license
* @link $HeadURL: https://xtpl.svn.sourceforge.net/svnroot/xtpl/trunk/ex8.php $
* @version $Id: ex8.php 21 2007-05-29 18:01:15Z cocomp $
*/
require_once('xtemplate.class.php');
$xtpl = new XTemplate('ex8.xtpl');
// Config
$num_columns = 5;
// This could be from e.g. num_rows from a database result set
$max_items = 26;
// End Config
$i = 0;
// Build the main table
while ($i < $max_items) {
$i ++;
// Assign the content
$xtpl->assign('stuff', array('item' => $i));
// Parse the cell
$xtpl->parse('main.table.row.cell');
// Use modulus of row length to decide if we wrap to next row
if (($i % $num_columns) == 0) {
$xtpl->parse('main.table.row');
}
}
// Deal with the last table row
$remainder = $i % $num_columns;
if (($remainder) != 0) {
// Wipe the last value (using for illustration only)
$xtpl->assign('stuff', array('item' => ' '));
// Add blank cells as needed to keep the table complete
for ($j = $remainder; $j < $num_columns; $j ++) {
$xtpl->parse('main.table.row.cell');
}
$xtpl->parse('main.table.row');
}
// Output
$xtpl->parse('main.table');
$xtpl->parse('main');
$xtpl->out('main');
?>