-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayments-views.php
178 lines (132 loc) · 4.11 KB
/
payments-views.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/*
VIEW.PHP
Displays all data from 'payments' table
*/
// header
include('header.php');
// connect to the database
include('linkupdb.php');
//display clean utf8 data
function clean_payments($str)
{
$str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
return $str;
}
// Sort by query results by each table header
$sorter = "";
if ($_GET['sort'] == 'customerDesc')
{
$sorter = "ORDER BY u.customerName DESC";
}
elseif ($_GET['sort'] == 'customerAsc')
{
$sorter = "ORDER BY u.customerName ASC";
}
elseif ($_GET['sort'] == 'checkNumber')
{
$sorter = "ORDER BY p.checkNumber";
}
elseif ($_GET['sort'] == 'paymentDate')
{
$sorter = "ORDER BY p.paymentDate";
}
elseif($_GET['sort'] == 'amount')
{
$sorter = "ORDER BY p.amount";
}
// number of results to show per page
$per_page = 20;
// figure out the total pages in the database
$result = mysql_query("SELECT p.customerNumber, p.checkNumber, p.paymentDate, p.amount, u.customerNumber, u.customerName FROM payments p, customers u WHERE p.customerNumber = u.customerNumber $sorter");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);
// check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
// make sure the $show_page value is valid
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
// error - show first set of results
$start = 0;
$end = $per_page;
}
}
else
{
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}
?>
<div id="payments" class="fixed-wrapper"><h1 class="affix">Payments</h1></div>
<div class="container">
<div class="content">
<div class="row">
<ul class="nav nav-pills">
<li class="badge pull-right"><a href="payments-export.php">Export Records <i class="icon-cloud-download"></i></a></li>
</ul>
<!-- payments Section -->
<div class="content">
<div class="row-fluid">
<div class="col-md-12 col-sm-12 col-xs-12">
<?php
// pagination
echo " <ul class='pagination'> ";
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<li><a href='payments-views.php?page=$i'>$i</a></li>";
}
echo "</ul> ";
?>
<table class='table table-condensed' >
<thead>
<tr>
<th colspan="2">customer Name <a href="payments-views.php?sort=customerDesc" ><i class="icon-sort-down"></i></a> <a href="payments-views.php?sort=customerAsc" ><i class="icon-sort-up"></i></a></th>
<th><a href="payments-views.php?sort=checkNumber" >checkNumber<i class="icon-sort"></i></a></th>
<th><a href="payments-views.php?sort=paymentDate" >paymentDate<i class="icon-sort"></i></a></th>
<th><a href="payments-views.php?sort=amount" >amount<i class="icon-sort"></i></a></th>
</tr>
</thead>
<tbody>
<?php
// display data in table
// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }
// echo out the contents of each row into a table
echo '<tr>';
echo '<td colspan="2"><b> ' . clean_payments(mysql_result($result, $i, 'customerName')) . ' </b></td>';
echo '<td>' . clean_payments(mysql_result($result, $i, 'checkNumber')) . '</td>';
echo '<td>' . clean_payments(mysql_result($result, $i, 'paymentDate')) . '</td>';
echo '<td>$' . clean_payments(mysql_result($result, $i, 'amount')) . '</td>';
echo "</tr>";
}
echo "</tbody>";
// close table>
echo "</table>";
// pagination
echo " <ul class='pagination'> ";
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<li><a href='payments-views.php?page=$i'>$i</a></li>";
}
echo "</ul> ";
?>
</div>
</div>
</div>
<ul class="nav nav-pills">
<li class="badge pull-right"><a href="payments-export.php">Export Records <i class="icon-cloud-download"></i></a></li>
</ul>
</div>
</div>
</div>