limit.php
1.26 KB
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
<pre>
<?php
exit;
# include parseCSV class.
require_once('../parsecsv.lib.php');
# create new parseCSV object.
$csv = new parseCSV();
# if sorting is enabled, the whole CSV file
# will be processed and sorted and then rows
# are extracted based on offset and limit.
#
# if sorting is not enabled, then the least
# amount of rows to satisfy offset and limit
# settings will be processed. this is useful
# with large files when you only need the
# first 20 rows for example.
$csv->sort_by = 'title';
# offset from the beginning of the file,
# ignoring the first X number of rows.
$csv->offset = 2;
# limit the number of returned rows.
$csv->limit = 3;
# Parse '_books.csv' using automatic delimiter detection.
$csv->auto('_books.csv');
# Output result.
// print_r($csv->data);
?>
</pre>
<style type="text/css" media="screen">
table { background-color: #BBB; }
th { background-color: #EEE; }
td { background-color: #FFF; }
</style>
<table border="0" cellspacing="1" cellpadding="3">
<tr>
<?php foreach ($csv->titles as $value): ?>
<th><?php echo $value; ?></th>
<?php endforeach; ?>
</tr>
<?php foreach ($csv->data as $key => $row): ?>
<tr>
<?php foreach ($row as $value): ?>
<td><?php echo $value; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>