MySQLTable.php
2.25 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace Tz\WordPress\Tools\MySQLTable;
function array2table($arr,$width = "100%")
{
$count = count($arr);
if($count > 0){
reset($arr);
$num = count(current($arr));
echo "<table border=\"0\"cellpadding=\"5\" cellspacing=\"0\" width=\"$width\" class=\"cbv-report-list\">\n";
echo "<thead>\n";
echo "<tr>\n";
foreach(current($arr) as $key => $value){
echo "<th valign='bottom'>";
echo $key." ";
echo "</th>\n";
}
echo "</tr>\n";
echo "</thead>\n";
echo "<tbody>\n";
$wi = 0;
while ($curr_row = current($arr)) {
$rclass = ($wi%2) ? "odd" : "";
echo "<tr class='".$rclass."'>\n";
$col = 1;
while (false !== ($curr_field = current($curr_row))) {
echo "<td>";
echo $curr_field." ";
echo "</td>\n";
next($curr_row);
$col++;
}
while($col <= $num){
echo "<td> </td>\n";
$col++;
}
echo "</tr>\n";
$wi++;
next($arr);
}
echo "</tbody>\n";
echo "</table>\n";
}
}
function CSVExport($arr) {
$out = "";
$count = count($arr);
if( $count > 0 ) {
reset($arr);
$num = count(current($arr));
$k = 0;
foreach(current($arr) as $key => $value){
if ($k > 0) {
$out .= ",";
}
$out .= '"'.str_replace( '"', '\"',$key).'"';
$k++;
}
$out .= "\n";
while ($curr_row = current($arr)) {
$col = 1;
while (false !== ($curr_field = current($curr_row))) {
if ($col > 1) {
$out .= ",";
}
$out .= '"'.str_replace( '"', '\"',$curr_field).'"';
next($curr_row);
$col++;
}
while($col <= $num) {
if ($col > 1) {
$out .= ",";
}
$out .= '""';
$col++;
}
$out .= "\n";
next($arr);
}
}
return $out;
}
?>