-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBorrowed.php
103 lines (52 loc) · 1.83 KB
/
Borrowed.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
{source}
<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*');
$query->from('Borrowed');
$db->setQuery($query);
$results = $db->loadAssocList();
// Get the name of each column in the table.
// Each array entry is a column name.
$columns = array_keys($results[0]);
// Print out a checkbox for each column.
echo "<form action='' method='POST'><div>";
foreach($columns as &$columnName) {
echo "<input id=\"" . $columnName . "\" name=\"" . $columnName . "\" type=\"checkbox\" value=\"" . $columnName . "\"style=\"display: inline\" /><label for=\"" . $columnName . "\"style=\"display: inline\">" . $columnName . "</label>";
}
// Print out the submit button.
echo "</div><div><input name=\"submit\" type=\"submit\" value=\"Submit\" /></div></form>";
// On submit,
if(isset($_POST['submit'])) {
// Get everything from the table.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('*'));
$query->from($db->quoteName('Borrowed'));
$db->setQuery($query);
$result = $db->loadObjectList();
// Create the table and the header row.
echo "<table>";
echo "<tr style=\"background-color:Gray;color:White\">";
foreach($columns as &$columnName) { if (JRequest::getVar($columnName) == $columnName) { echo "<th>" . $columnName . "</th>";
}
}
echo "</tr>";
// Print out each row of data
foreach ($result as &$row) {
// Print out each column that was checked. If the column was not checked, print out a blank column.
echo "<tr>";
foreach($columns as &$columnName)
{
if (JRequest::getVar($columnName) == $columnName) {
echo "<td>" . $row->$columnName . "</td>";
}
}
echo "</tr>";
// Close out the row.
}
echo "</table>";
// Close out the table at the end of the loop.
}
?>
{/source}